简体   繁体   中英

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:. 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 .

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 .

I hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM