自定义视图切换效果

 先创建一个UIStoryboardSegue子类并覆盖perform方法。在perform方法中,拿到指向源视图控制器的主视图图层的指针,然后实现自定义切换动画(使用Core Animation)。一旦动画完成,就可以推送(push)到目标视图控制器(可以从联线对象中获得一个指向该视图控制器的指针)。

#import "CustomSegue.h"

@implementation CustomSegue
-(void)perform
{
    UIViewController*src=(UIViewController*)self.sourceViewController;
    UIViewController*dest=(UIViewController*)self.destinationViewController;
    
    CGRect f=src.view.frame;
    CGRect oringinalSourceRect=src.view.frame;
    f.origin.y=f.size.height;
    
    [UIView animateWithDuration:5 animations:^{src.view.frame=f;} completion:^(BOOL finished){
        src.view.alpha=0;
        dest.view.frame=f;
        dest.view.alpha=0.0;
        [[src.view superview]addSubview:dest.view];//窗口添加子视图
        
        [UIView animateWithDuration:5 animations:^{dest.view.frame=oringinalSourceRect; dest.view.alpha=1.0;} completion:^(BOOL finished){
            [dest.view removeFromSuperview];
            src.view.alpha=1.0f;
            [src.navigationController pushViewController:dest animated:NO];
        }];
    }];
}

@end

 

你可能感兴趣的:(自定义视图切换效果)