生活随笔
收集整理的這篇文章主要介紹了
UIViewController详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
UIViewController類詳解:
通過Nib文件初始化
[objc]?view plaincopy
init(nibName?nibName:?String?,?bundle?nibBundle:?NSBundle?)?? println("nibName?=?\(self.nibName)")?????????????????????????????????????? println("nibBundle?=?\(self.nibBundle)")??????????????????????????????????
StoryBoard相關
[objc]?view plaincopy
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)?? }??
[objc]?view plaincopy
?? override?func?canPerformUnwindSegueAction(action:?Selector,?fromViewController:?UIViewController,?withSender?sender:?AnyObject)?->?Bool?{???? }??
[objc]?view plaincopy
?? override?func?segueForUnwindingToViewController(toViewController:?UIViewController,?fromViewController:?UIViewController,?identifier:?String?)?->?UIStoryboardSegue?{?? }??
[objc]?view plaincopy
?? func?viewControllerForUnwindSegueAction(action:?Selector,?fromViewController:?UIViewController,?withSender?sender:?AnyObject?)?->?UIViewController??{?? }??
Unwindsegue的實現原理請參考相關文章
View相關
[objc]?view plaincopy
println("view?=?\(view)")?? println("view?is?loaded?=?\(isViewLoaded())")?? title?=?"ViewController"<pre?name="code"?class="objc">?? ????super.loadView()<pre?name="code"?class="objc">}??
[objc]?view plaincopy
override?func?viewDidLoad()?{??
[objc]?view plaincopy
????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)?? }??
模式跳轉
[objc]?view plaincopy
?? ?? viewController.modalTransitionStyle?=?.FlipHorizontal?? ?? viewController.modalPresentationStyle?=?.FullScreen?? ?? viewController.modalPresentationCapturesStatusBarAppearance?=?true?? ?? viewController.disablesAutomaticKeyboardDismissal()?? ?? presentViewController(viewController,?animated:?true)?{?()?->?Void?in?? ?????? }?? dismissViewControllerAnimated(true?,?completion:?{?()?->?Void?in?? ?????? ?????? })??
配置View的layout
[objc]?view plaincopy
?? override?func?viewWillLayoutSubviews()?{?? ????super.viewWillLayoutSubviews()?? }?? ?? ?override?func?viewDidLayoutSubviews()?{?? ????super.viewDidLayoutSubviews()?? }<pre?name="code"?class="objc">??
updateViewConstraints()
[objc]?view plaincopy
?? 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??
跳轉相關
[objc]?view plaincopy
isBeingPresented()???????????????????????????????????????????????????????? isBeingDismissed()???????????????????????????????????????????????????????? ?????????? isMovingToParentViewController()?? isMovingFromParentViewController()??
旋轉相關
[objc]?view plaincopy
?? override?func?shouldAutorotate()?->?Bool?{?? ????return?true?? }?? ?? override?func?supportedInterfaceOrientations()?->?Int?{?? ????return?2?? }?? ?? override?func?preferredInterfaceOrientationForPresentation()?->?UIInterfaceOrientation?{?? ????return?.Portrait?? }??
自定義的ViewController Container
[objc]?view plaincopy
?? ?? 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;?? }??
恢復相關
[objc]?view plaincopy
restorationIdentifier?恢復標示?? restorationClass??????恢復的類?? override?func?encodeRestorableStateWithCoder(coder:?NSCoder)?{?? ?????????? }?? override?func?decodeRestorableStateWithCoder(coder:?NSCoder)?{?? ?????????? }?? applicationFinishedRestoringState()?恢復完成??
獲得其他的ViewController
[objc]?view plaincopy
println("parentViewController=\(self.parentViewController)")?????????????? println("presentedViewController=\(self.presentedViewController)")???????? println("presentingViewController=\(self.presentingViewController)")?????? ?? ?? ?? ?? ??
StatusBar相關
[objc]?view plaincopy
?? 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相關
[objc]?view plaincopy
override?func?setToolbarItems(toolbarItems:?[AnyObject]?,?animated:?Bool)?{?? ?????????? }?? self.navigationItem?? self.editButtonItem()?? hidesBottomBarWhenPushed?=?true?? self.toolbarItems?=?nil??
TabBar相關
[objc]?view plaincopy
self.toolbarItems??
常量
[objc]?view plaincopy
UIModalTransitionStyle?? Modal?Presentation?Styles?? UIViewControllerHierarchyInconsistencyException?? UIViewControllerShowDetailTargetDidChangeNotification ?
總結
以上是生活随笔為你收集整理的UIViewController详解的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。