【问题标题】:moving UIScrollView on rotate on the ipad在 iPad 上旋转时移动 UIScrollView
【发布时间】:2011-06-01 23:07:10
【问题描述】:

我有一个多视图应用程序,并且我已经构建了一个自定义面板视图控制器来显示具有有限产品信息的面板,问题是应该有 3 个纵向面板和 4 个横向面板。

由于视图控制器的深度(大约 5 个),didRotateFromInterfaceOrientation: 事件不会在子视图控制器上触发,因此我使用 rootViewController 上的 NSNotificationCenter 来发布消息并使用子控制器接收它。

我可以毫无问题地移动面板 (UIScrollViews),但它们会在我希望它们移动到位时移动,但它们会立即移动,不平滑或不整齐,我希望它们滑入新位置。

经过一番搜索,我仍然无法找到如何做到这一点。

-(void) updatePanelLocations{
    int buttonWidth = 230;
    int buttonHeight = 335;
    float frameWidth = mainPanel.frame.size.width;
    int numberOfcolumns = frameWidth / buttonWidth;
    float margin = (frameWidth - (numberOfcolumns * buttonWidth)) / (numberOfcolumns +1);
    int currentRow = 0;
    int currentColumn = 0;

    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];
    [animation setType:kCATransitionReveal];
    [animation setDuration:0.4];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];

    int i = 0;

    for (UIView* curView in [mainPanel subviews]) {
        //set an arbutrary tag field in generating the scrollviews so i can detect this
        if (curView.tag != 9991) continue;
        //newline detection
        if (currentColumn == numberOfcolumns){
            currentRow++;
            currentColumn = 0;
        }

        [[curView layer] addAnimation:animation forKey:@"transitionViewAnimation"]; 

        //XY Coordinates
        int buttonX = (margin * (currentColumn + 1)) + (buttonWidth * currentColumn);
        int buttonY = (margin * (currentRow + 1)) + (buttonHeight * currentRow);

        //make the frame
        [curView setFrame:CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight)];        
        [curView setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
        //put the button on the target uiscrollview
        [[curView layer] removeAnimationForKey:@"transitionViewAnimation"];
        //next column
        currentColumn++;

        i++;
    }

    animation = nil;
}

如何为这种从 a 滑到 b 的动作设置动画??

或者如果我都错了,请指出我正确的方向:)

干杯

【问题讨论】:

    标签: iphone ipad animation uiview xcode4


    【解决方案1】:

    您正在寻找的是UIViewanimateWithDuration: 方法。

    您将从视图控制器中的willRotateToInterfaceOrientation:duration: 获得适当的持续时间。

    【讨论】:

    • 太棒了,而且真的很整洁,我的方法有点缩水了。谢谢。
    猜你喜欢
    • 2011-05-06
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多