UIViewController类详解:
通过Nib文件初始化
StoryBoard相关
Unwindsegue的实现原理请参考相关文章
View相关
println("view = \(view)")
println("view is loaded = \(isViewLoaded())")
title = "ViewController"<pre name="code" class="objc">//如果不是nib文件初始化而来,初始化的时候需要调用这个方法初始化view,此方法不能主动调用,是系统调用的<pre name="code" class="objc">override func loadView() {
super.loadView()<pre name="code" class="objc">}//view初始化以后调用
模式跳转
- viewController.modalTransitionStyle = .FlipHorizontal
- viewController.modalPresentationStyle = .FullScreen
- viewController.modalPresentationCapturesStatusBarAppearance = true
- viewController.disablesAutomaticKeyboardDismissal()
-
- presentViewController(viewController, animated: true) { () -> Void in
-
- }
- dismissViewControllerAnimated(true , completion: { () -> Void in
-
-
- })
配置View的layout
- override func viewWillLayoutSubviews() {
- super.viewWillLayoutSubviews()
- }
- override func viewDidLayoutSubviews() {
- super.viewDidLayoutSubviews()
- }<pre name="code" class="objc">
updateViewConstraints()
- if self.respondsToSelector(Selector("edgesForExtendedLayout")) {
- self.edgesForExtendedLayout = .None
- }
- if self.respondsToSelector(Selector("automaticallyAdjustsScrollViewInsets")) {
- self.automaticallyAdjustsScrollViewInsets = true
- }
- if self.respondsToSelector(Selector("extendedLayoutIncludesOpaqueBars")) {
- self.extendedLayoutIncludesOpaqueBars = false
- }
-
- self.preferredContentSize = self.view.bounds.size
跳转相关
- isBeingPresented()
- isBeingDismissed()
-
- isMovingToParentViewController()
- isMovingFromParentViewController()
旋转相关
- override func shouldAutorotate() -> Bool {
- return true
- }
- override func supportedInterfaceOrientations() -> Int {
- return 2
- }
- override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
- return .Portrait
- }
自定义的ViewController Container
- func addChildViewController(childController: UIViewController) {
-
- }
- func removeFromParentViewController() {
-
- }
-
- }
- func willMoveToParentViewController(parent: UIViewController?) {
-
- }
- func didMoveToParentViewController(parent: UIViewController?) {
-
- }
- func beginAppearanceTransition(isAppearing: Bool, animated: Bool) {
-
- }
- func endAppearanceTransition() {
-
- }
- func childViewControllerForStatusBarStyle() -> UIViewController? {
- return nil;
- }
- func childViewControllerForStatusBarHidden() -> UIViewController? {
- return nil;
- }
恢复相关
- restorationIdentifier 恢复标示
- restorationClass 恢复的类
- override func encodeRestorableStateWithCoder(coder: NSCoder) {
-
- }
- override func decodeRestorableStateWithCoder(coder: NSCoder) {
-
- }
- applicationFinishedRestoringState() 恢复完成
获得其他的ViewController
- println("parentViewController=\(self.parentViewController)")
- println("presentedViewController=\(self.presentedViewController)")
- println("presentingViewController=\(self.presentingViewController)")
StatusBar相关
- viewController.modalPresentationCapturesStatusBarAppearance = true
- func childViewControllerForStatusBarStyle() -> UIViewController? {
- return nil;
- }
- func childViewControllerForStatusBarHidden() -> UIViewController? {
- return nil;
- }
- override func preferredStatusBarStyle() -> UIStatusBarStyle {
- return .Default
- }
- override func prefersStatusBarHidden() -> Bool {
- return true
- }
- override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
- return .Fade
- }
Navigation相关
- override func setToolbarItems(toolbarItems: [AnyObject]?, animated: Bool) {
-
- }
- self.navigationItem
- self.editButtonItem()
- hidesBottomBarWhenPushed = true
- self.toolbarItems = nil
TabBar相关
常量
- UIModalTransitionStyle
- Modal Presentation Styles
- UIViewControllerHierarchyInconsistencyException
- UIViewControllerShowDetailTargetDidChangeNotification
|
请发表评论