UIViewController详解--Swift版本
来源:互联网 发布:sql查询语句实例股票 编辑:程序博客网 时间:2024/06/04 18:01
UIViewController类详解:
通过Nib文件初始化
- init(nibName nibName: String?, bundle nibBundle: NSBundle?)
- println("nibName = \(self.nibName)")
- println("nibBundle = \(self.nibBundle)")
StoryBoard相关- println("storyboard = \(self.storyboard)")
- override func shouldPerformSegueWithIdentifier(identifier: String?, sender: AnyObject?) -> Bool {
- return true
- }
-
- override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
- print("prepareForSegue")
- }
-
- override func performSegueWithIdentifier(identifier: String?, sender: AnyObject?) {
- super.performSegueWithIdentifier(identifier!, sender: sender)
- }
-
- override func canPerformUnwindSegueAction(action: Selector, fromViewController: UIViewController, withSender sender: AnyObject) -> Bool {
- }
-
- override func segueForUnwindingToViewController(toViewController: UIViewController, fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue {
- }
-
- func viewControllerForUnwindSegueAction(action: Selector, fromViewController: UIViewController, withSender sender: AnyObject?) -> UIViewController? {
- }
Unwindsegue的实现原理请参考相关文章View相关
- println("view = \(view)")
- println("view is loaded = \(isViewLoaded())")
- title = "ViewController"<pre name="code" class="objc">
- super.loadView()<pre name="code" class="objc">}
- override func viewDidLoad() {
- super.viewDidLoad() <span style="font-family: Arial, Helvetica, sans-serif;">
- } <pre name="code" class="objc">override func viewWillAppear(animated: Bool) {
- super.viewWillAppear(animated)
- }
-
-
- override func viewDidAppear(animated: Bool) {
- super.viewDidAppear(animated)
- }
-
-
- override func viewWillDisappear(animated: Bool) {
- super.viewWillDisappear(animated)
- }
-
-
- override func viewDidDisappear(animated: Bool) {
- super.viewDidDisappear(animated)
- }
模式跳转
-
-
- 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
0 0