美文网首页iOS定制viewiOS DeveloperiOS 开发
iOS viewController的推出方式 pop dism

iOS viewController的推出方式 pop dism

作者: Fiona_L | 来源:发表于2016-05-19 16:08 被阅读1141次

在iOS中页面推出有两种方式推出页面

  1. popViewControllerAnimated
  2. dismissViewControllerAnimated

Pop

  • 只能用于navigationcontroller,
  • popViewControllerAnimated对应于pushViewController
  • push的页面才可以通过pop推出

Dismiss

  • 可以用于任意viewcontroller
  • dismissViewControllerAnimated对应于presentViewController
  • 使用present的页面可以通过dismiss推出

使用present推出页面的方式

present页面的代码如下:

ViewController * presentVC = [[ViewController alloc] init];
    [self presentViewController: presentVC animated:NO completion:^{
        NSLog(@"present");
    }];

如果想要设置present的动画效果,可以如下设置:

presentVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; //此处应当设置被present的页面而不是当前页面

查看代码可以知道present动画有如下四种:

typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {
    UIModalTransitionStyleCoverVertical = 0,
    UIModalTransitionStyleFlipHorizontal __TVOS_PROHIBITED,
    UIModalTransitionStyleCrossDissolve,
    UIModalTransitionStylePartialCurl NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
};

默认第一种。
此外还有UIModalPresentationStyle,用法类似。
更多详细信息可参考苹果官方文档

相关文章

网友评论

  • Hello_kid:从A页面推出B页面,在B页面,用[b dismiss ]也可以,用[b.presentingViewController dismiss] 也可以,但是俩个对象不一样,b代表b对象,b.presentingViewController 代表a对象; 怎么推出正确的用法是什么呢? 网上说,谁推入的,就谁推出;
  • feng_dev:present 出的界面一定 是从下往上推出的吗
    feng_dev:@Fiona_L 嗯嗯。 原来是这样
    Fiona_L:@枫子哥 多谢你提出这个啊!我之前确实没有注意过。我看了一下不是的,可以定义四种方式,默认是从底部推出。具体的我更新在文章中了。

本文标题:iOS viewController的推出方式 pop dism

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