zoukankan      html  css  js  c++  java
  • iOS中的场景转换机制的浅显分析

    目前Apple推荐的场景转换的方法有以下几个:

    一般的跳转方法:

    presentViewController

    Discussion

    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.

    要点:传统的模态跳转方法

    dismissViewControllerAnimated

    Discussion

    The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller.

    If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

    If you want to retain a reference to the receiver'€™s presented view controller, get the value in the presentedViewController property before calling this method.

    The completion handler is called after the viewDidDisappear: method is called on the presented view controller.

    要点:与presentViewController搭配使用

    使用导航栏/Split View时使用的方法:

    showViewController

    Discussion

    This method is used in conjunction with UISplitViewController and UINavigationController. When this method is called, it calls targetViewControllerForAction:sender: on itself and calls this method on the returned object. The target object can then display the view controller in an appropriate way. For example, a navigation controller pushes the view controller on its navigation stack.

    If the targetViewControllerForAction:sender: method returns nil, this method uses the root of the currently presented view controller chain to present vc modally.

    要点:用于UISplitViewController 、UINavigationController时相当于调用push。如果不是这两者,则相当于presentViewController

    showDetailViewController

    Discussion

    This method is used in conjunction with UISplitViewController and UINavigationController. When this method is called, it calls targetViewControllerForAction:sender: on itself and calls this method on the returned object. The target object can then display the view controller in an appropriate way. For example, a split view controller tries to display the view controller in its secondary view controller slot. If a secondary view controller already exists in that slot, that view controller is asked to present vc in an appropriate way.

    If the targetViewControllerForAction:sender: method returns nil, this method uses the root of the currently presented view controller chain to present vc modally.

    要点:iPad和6+横屏下SplitView可以显示两个ViewController,使用此方法

    pushViewController

    Pushes a view controller onto the receiver’s stack and updates the display.

    iOS 8 后 Apple 不再提倡使用UINavigationController 的 pushViewController:animated: 方法了

    使用show替代

    popViewControllerAnimated

    popToRootViewControllerAnimated

    popToViewController

    上面三个方法是push/show对应出栈方法

    另外

    注意点

    在导航控制器的应用中,可以这样方便的访问到上一个控制器:

       1:  let a = navigationController!.viewControllers
       2:  let c = a[a.count - 2] as! ContactListViewController

    进而可以对其上一个控件进行一些修改

    viewControllers属性的说明Apple鼓励我们使用这个属性获取当前导航栏的根控制器(0)、上一级控制器(n-2)以及顶层(n-1)控制器

    Property
    The view controllers currently on the navigation stack.

    Declaration
    SWIFT
    var viewControllers: [AnyObject]!
    OBJECTIVE-C
    @property(nonatomic, copy) NSArray *viewControllers

    Discussion

    The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.

    Assigning a new array of view controllers to this property is equivalent to calling the setViewControllers:animated: method with the animated parameter set to NO.

    Ref:

    http://www.cocoachina.com/ios/20141113/10212.html

    http://www.cnblogs.com/iMiamas/p/4282568.html

    http://stackoverflow.com/questions/28498947/difference-between-pushviewcontroller-and-showviewcontroller

    http://mobile.51cto.com/iphone-446761.htm

    https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/index.html

    http://blog.csdn.net/dreamno23/article/details/21085783

  • 相关阅读:
    POJ--2356 Find a multiple
    Trailing Zeroes (III)
    第一章 快速入门
    第二章 变量和基本类型
    第三章 标准库类型
    第四章 数组和指针
    第五章 表达式
    第六章 语句
    第七章 函数
    第八章 标准IO库
  • 原文地址:https://www.cnblogs.com/zeyang/p/4491909.html
Copyright © 2011-2022 走看看