美文网首页iOS开发技术iOSiOS入门学习
presentViewController之系统动画

presentViewController之系统动画

作者: FlowYourHeart | 来源:发表于2017-05-02 14:26 被阅读1191次

    东西多了,脑子不够存,当需要的时候,总是觉得好像知道,却又不是真的知道,去找资料,看文档都是在浪费时间。那就清理一下脑存吧。方便以后用。

    present动画.gif
    • 在UIViewController.h中有这样一个枚举
    typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {
        UIModalTransitionStyleCoverVertical = 0,
        UIModalTransitionStyleFlipHorizontal __TVOS_PROHIBITED,
        UIModalTransitionStyleCrossDissolve,
        UIModalTransitionStylePartialCurl NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
    };
    
    • 效果图上按钮依次对应的方法
    //UIModalTransitionStyleCoverVertical
    - (IBAction)coverVertical:(id)sender {
        BViewController *bvc = [[BViewController alloc] init];
        
        bvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        
        [self presentViewController:bvc animated:YES completion:nil];
        
    }
    
    //UIModalTransitionStyleFlipHorizontal
    - (IBAction)flipHorizontal:(id)sender {
        BViewController *bvc = [[BViewController alloc] init];
        
        bvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        
        [self presentViewController:bvc animated:YES completion:nil];
    }
    
    //UIModalTransitionStyleCrossDissolve
    - (IBAction)crossDissolve:(id)sender {
        BViewController *bvc = [[BViewController alloc] init];
        
        bvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        
        [self presentViewController:bvc animated:YES completion:nil];
    }
    
    //UIModalTransitionStylePartialCurl
    - (IBAction)partialCurl:(id)sender {
        BViewController *bvc = [[BViewController alloc] init];
        
        bvc.modalTransitionStyle = UIModalTransitionStylePartialCurl;
        
        [self presentViewController:bvc animated:YES completion:nil];
    }
    
    • 有前进就有后退

      从A控制器present到B再到C控制器,现在想要从C直接回到A,怎么办呢?首先需要知道的是:A 是 B的presentingViewController,B 是 A的presentedViewController,同样B 是 C的presentingViewController,C 是 B的presentedViewController。这样就能很好的理解每一次的present,前后控制器都有关联的,后退也就简单了。代码如下:

    - (void)gobackAction {
        UIViewController *rootVC = self.presentingViewController;
        UIViewController *bottomVC;
        while (rootVC) {
            bottomVC = rootVC;
            rootVC = rootVC.presentingViewController;
            
            NSLog(@"有:%s,%s",object_getClassName(bottomVC),object_getClassName(rootVC));
        }
        [bottomVC dismissViewControllerAnimated:YES completion:nil];
        
    }
    

    相关文章

      网友评论

        本文标题:presentViewController之系统动画

        本文链接:https://www.haomeiwen.com/subject/ruvctxtx.html