UIView transitionWithView:不工作

时间:2011-08-20 09:19:32

标签: ios uiview uiviewanimation uiviewanimationtransition

我正在制作漫画书应用的布局编辑器。漫画书的页面被分成行,然后每行至少有一列。当用户在列上执行垂直滑动时,它应该分成两个单独的列。这部分工作正常,但我想使用+ transitionWithView:添加一个简单的卷曲过渡。一切仍然正常(列很好地划分)但没有动画。这是代码:

- (void)divideColumnView:(CCLayoutColumnView *)columnView atPoint:(CGPoint)_divisionPoint {
// divides a single column into two smaller ones

// define frames for new columns
CGRect frameLeft = columnView.frame;
CGRect frameRight = frameLeft;
CGFloat width = _divisionPoint.x - frameLeft.origin.x;
frameLeft.size.width = width;
frameRight.size.width -= width;
frameRight.origin.x += width;


// set up the container for transition
UIView *rowView = [columnView superview];
UIView *containerView = [[UIView alloc] initWithFrame:columnView.frame];
[rowView addSubview:containerView];

// move the column to the container
columnView.frame = [containerView convertRect:columnView.frame fromView:rowView];
[containerView addSubview:columnView];

// set up columns that will be inserted to the container during transition
CCLayoutColumnView *leftColumnView = [[CCLayoutColumnView alloc] initWithFrame:[containerView convertRect:frameLeft fromView:rowView]];
CCLayoutColumnView *rightColumnView = [[CCLayoutColumnView alloc] initWithFrame:[containerView convertRect:frameRight fromView:rowView]];

[UIView transitionWithView:containerView
                  duration:0.5
                   options:UIViewAnimationOptionTransitionCurlUp
                animations:^{
                    [columnView removeFromSuperview];
                    [containerView addSubview:leftColumnView];
                    [containerView addSubview:rightColumnView];
                }
                completion:^(BOOL finished){
                    // add columns to their row
                    leftColumnView.frame = frameLeft;
                    rightColumnView.frame = frameRight;
                    [rowView addSubview:leftColumnView];
                    [rowView addSubview:rightColumnView];

                    // clean up
                    [containerView removeFromSuperview];
                    [containerView release];
                    [leftColumnView release];
                    [rightColumnView release];
                }];

}

我已经检查了所有视图的几何图形,看起来没问题。此外,正确执行完成块。

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

我还坚持用transitionWithView设置动画视图。

我不知道您项目的层次结构,但如果您可以为要为其设置动画的视图创建单独的类,则很容易:

[UIView transitionWithView:self.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{} completion:^(BOOL f){}];

works..i.e。此功能适用于self.view

我希望它有所帮助。