[英]UIView transitionWithView: not working
I'm making a layout editor for a comic book app. 我正在为漫画书应用程序设计布局。 The page of the comic book is divided into rows and then each row has at least one column. 漫画书的页面分为几行,然后每一行至少有一列。 When the user performs a vertical swipe over a column, it's supposed to divide into two separate columns. 当用户在列上进行垂直滑动时,应该将其分为两个单独的列。 This part already works fine, but I wanted to add a simple curl-up transition for that using +transitionWithView:. 该部分已经可以正常工作,但是我想使用+ transitionWithView:为此添加一个简单的向上卷曲过渡。 Everything still works fine (the column divides nicely) but there's no animation. 一切仍然正常(该列划分很好),但是没有动画。 Here's the code: 这是代码:
- (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];
}];
} }
I already checked the geometry of all views and it seems ok. 我已经检查了所有视图的几何形状,看起来还可以。 Also, the completion block is executed properly. 另外,完成块可以正确执行。
What may be the problem? 可能是什么问题?
I was also stuck at animating views with transitionWithView
. 我还被困在使用transitionWithView
为视图设置动画的transitionWithView
。
I don't know the hierarchy of your project, but if it is possible for you to create a separate class for the view you want to animate with this, it would be easy: 我不知道您的项目的层次结构,但是如果您可以为要为其创建动画的视图创建一个单独的类,那将很容易:
[UIView transitionWithView:self.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{} completion:^(BOOL f){}];
works..ie this function works properly with self.view
. works..ie此功能与正常工作self.view
。
I hope it helps. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.