UIView transition animation

2019-04-02 06:11发布

问题:

ViewB and ViewC are subviews of ViewA. Say ViewB is currently on top of ViewC. I would like to bring ViewC on top with flipping animation as shown in the diagram. I use the UIView class method (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion. However, the ViewA gets flipped along with viewB which is not the desired behavior. The desired behavior is only for ViewB to flip over and ViewC is now on top. Any idea how to achieve the desired behavior?

回答1:

Try this :

 -(void)FilpAnimation
    {
        viewObjB.alpha=1.0;
        viewObjB.hidden=NO;
        [UIView transitionWithView:viewObjB
                          duration:1.5
                           options:UIViewAnimationOptionTransitionFlipFromRight
                        animations:^{
                            viewObjB.hidden=YES;
                            viewObjB.alpha=0.0;
                        } completion:nil];

        viewObjC.alpha=0.0;
        viewObjC.hidden=YES;
        [UIView transitionWithView:viewObjC
                          duration:1.5
                           options:UIViewAnimationOptionTransitionFlipFromLeft
                        animations:^{
                            viewObjC.hidden=NO;
                            viewObjC.alpha=1.0;
                        } completion:nil];    
    }