在ipad上旋转移动UIScrollView

时间:2011-06-01 23:07:11

标签: iphone ipad animation uiview xcode4

我有一个多视图应用程序,我已经构建了一个自定义的panelview控制器来显示有关产品信息有限的面板,问题是应该有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 ??

或者更好的是,如果我把它全部弄错了,请指出正确的方向:)

干杯

1 个答案:

答案 0 :(得分:1)

您正在寻找的是UIView的{​​{1}}方法。

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