presentViewController:animated:completion:的特殊之处

原型:

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion

描述:

Presents a view controller modally.
  In a horizontally compact environment, the presented view is always full screen. In a horizontally regular environment, the presentation depends on the value in the modalPresentationStyle property.
    This method sets the presentedViewController property to the specified view controller, resizes that view controller‘??s view based on the presentation style and then adds the view to the view hierarchy. The view is animated onscreen according to the transition style specified in the modalTransitionStyle property of the presented view controller.
The completion handler is called after the viewDidAppear: method is called on the presented view controller.

注意上面红色文字的地方。

一般来说,页面跳转必须在viewDidLoad和viewDidAppear之后才能进行,如果是在presentViewController:animated:completion:的completion中跳转,可以确保页面跳转是在viewDidAppear之后进行的。否则,就会有可能提示Warning: Attempt to present on whose view is not in the window hierarchy!

参考:

对Warning: Attempt to present on whose view is not in the window hierarchy!的解决方案

时间: 2024-08-28 17:26:15

presentViewController:animated:completion:的特殊之处的相关文章

PresentViewController切换界面

视图切换,没有NavigationController的情况下,一般会使用presentViewController来切换视图并携带切换时的动画, 其中切换方法如下: – presentViewController:animated:completion: 弹出,出现一个新视图 可以带动画效果,完成后可以做相应的执行函数经常为nil– dismissViewControllerAnimated:completion:退出一个新视图 可以带动画效果,完成后可以做相应的执行函数经常为nil 切换动画

pushViewController, popViewController, presentViewController, dismissViewController---关于视图跳转的总结

1.[self.view addSubView:view];和[self.window addSubView:view];需要注意,此方法只是把页面(view)加在当前页面(view)上,控制器(viewController)还是原来那个控制器.此时再用[self.navigationColler pushViewController:animated:];和 [self.navigationController popViewControllerAnimated:]; 是不行的.要想使用pus

PresentViewController切换界面(一些系统自带的页面切换动画)

视图切换,没有NavigationController的情况下,一般会使用presentViewController来切换视图并携带切换时的动画, 其中切换方法如下: – presentViewController:animated:completion: 弹出,出现一个新视图 可以带动画效果,完成后可以做相应的执行函数经常为nil– dismissViewControllerAnimated:completion:退出一个新视图 可以带动画效果,完成后可以做相应的执行函数经常为nil 切换动画

UIView 视图切换

UIView之间常用视图之间切换方式 转载自:http://www.jianshu.com/p/0d53f9402c07 在平时编写代码的过程中,页面之间的跳转可以说就和MVC模式一样是开发必须的.但是可能我们知道一种或者几种页面之间的跳转,今天我就来总结一下我在开发之中遇到的所有的页面跳转代码.(关于控制器之间的简单的跳转,比如导航控制器跳转.故事版跳转.简单的模态跳转不在这里多说) 一.代理跳转. 通常我们在跳转中经常是通过你点击了某个事件或者某个操作使你进行控制器之间的跳转.那么我们可以在

iOS自定义转场动画实战讲解

iOS自定义转场动画实战讲解 转场动画这事,说简单也简单,可以通过presentViewController:animated:completion:和dismissViewControllerAnimated:completion:这一组函数以模态视图的方式展现.隐藏视图.如果用到了navigationController,还可以调用pushViewController:animated:和popViewController这一组函数将新的视图控制器压栈.弹栈. 下图中所有转场动画都是自定义的

移动开发(IOS) – UIKit框架

1.UIView 1.1.所有 UI 控件都继承自 UIView. 1.2.每一个 UIView 都是一个容器,可以容纳其他 UIView.其中容器视图被称为父视图,而被包含的视图或者控件被成为子视图或者子控件. 1.3.视图对应的文件通常是 storyboard 或者 xib 文件.在许多 iOS 应用程序中,通常不必为视图编写任何代码. 1.4.UIView 负责界面的显示. 1.5.常用属性: superview 获得自己的父控件对象 subviews 获得自己的所有子控件对象 一个视图最

自定义转场动画--Swift3.0版本

转场动画这事,说简单也简单,可以通过presentViewController:animated:completion:和dismissViewControllerAnimated:completion:这一组函数以模态视图的方式展现.隐藏视图.如果用到了navigationController,还可以调用pushViewController:animated:和popViewController这一组函数将新的视图控制器压栈.弹栈. 下图中所有转场动画都是自定义的动画,这些效果如果不用自定义动

iOS UIViewController API解读

/*UIViewController is a generic controller base class that manages a view. It has methods that are calledwhen a view appears or disappears. Subclasses can override -loadView to create their custom view hierarchy, or specify a nib name to be loadedaut

UIViewController全部API的学习。

/* UIViewController is a generic controller base class that manages a view.  It has methods that are called when a view appears or disappears. Subclasses can override -loadView to create their custom view hierarchy, or specify a nib name to be loaded