http://www.panduoduo.net/u/bd-369186934/2 ios
UIViewController提供了一個基礎的視圖管理模型,能夠用UIViewController管理視圖的繼承,及對view的管理。併發
屬性:app
view:視圖 (UIViewController的一個屬性,用於UI控件的存放和操做)ide
viewIfLoaded:是否加載視圖成功 (是一個只讀屬性,若是加載成功則返回視圖控制器的視圖,若是沒有加載成功則返回空值。iOS9加入)佈局
nibName:nib視圖的名字 (只讀)動畫
nibBundle:nib視圖的位置 (只讀)ui
storyboard:故事版 (只讀)url
title:標題 (在父視圖控制器上面使用效果和self.navigationItem.title同樣)spa
parentViewController:父視圖控制器 (只讀)
.net
modalViewController:模態視圖 (已經被presentedViewController取代,只讀)
presentedViewController:被本視圖present出來的視圖控制器 (只讀)
presentingViewController:present出本視圖控制器的視圖控制器 (只讀)
definesPresentationContext:本視圖控制器的視圖是否被覆蓋時,視圖控制器或它的子類提供了一個視圖控制器。
providesPresentationContextTransitionStyle:是否設定視圖在present使用不一樣的風格
modalTransitionStyle:過渡風格 (取值爲:UIModalTransitionStyle一共有4種狀況:UIModalTransitionStyleCoverVertical:從下向上徐徐彈出,關閉時向下隱,UIModalTransitionStyleFlipHorizontal:水平旋轉的方式顯示,UIModalTransitionStyleCrossDissolve:漸變方式,UIModalTransitionStylePartialCurl:翻頁)
modalPresentationStyle:彈出風格 (取值爲:UIModalPresentationStyle一共有9種狀況:UIModalPresentationFullScreen,UIModalPresentationPageSheet,UIModalPresentationFormSheet,UIModalPresentationCurrentContext,UIModalPresentationCustom,UIModalPresentationOverFullScreen,UIModalPresentationOverCurrentContext,UIModalPresentationPopover,UIModalPresentationNone)
modalPresentationCapturesStatusBarAppearance:設置狀態欄是否在屏幕滾動的時候隱藏,默認是NO(iOS7加入)
wantsFullScreenLayout:iOS7已經被棄用
edgesForExtendedLayout:指定邊緣延伸的方向 (取值爲:UIRectEdge 通常在有nav的狀況下使用時候延伸到nav下方iOS7加入)
extendedLayoutIncludesOpaqueBars:屏幕滑動時下方的視圖是否穿過導航欄 (ios7 加入)
automaticallyAdjustsScrollViewInsets:效果和extendedLayoutIncludesOpaqueBars相似
preferredContentSize: 設置子視圖控制器的大小 (iOS7加入)
interfaceOrientation:當前程序界面旋轉的方向 (取值爲:UIInterfaceOrientation 有5種屏幕旋轉的狀況)
editing:是否容許編輯
searchDisplayController:搜索框
childViewControllers:子視圖控制器字典 (取值是NSArray)
restorationIdentifier:保存標題 恢復標識符 (取值是NSString)
restorationClass: 回覆類
topLayoutGuide:用於autolayout中 表示狀態欄底部的位置 (只讀 iOS7加入)
bottomLayoutGuide:用於autolayout中 表示屏幕底部的位置 (只讀 iOS7加入)
extensionContext:擴展上下文 (不懂,iOS8加入)
presentationController:被present出來的視圖控制器 (只讀,iOS8加入)
popoverPresentationController: 被pop出來的視圖控制器 (只讀,iOS8加入)
previewingGestureRecognizerForFailureRelationship:預覽失敗手勢 (使用3Dtouch的時候配合使用,能夠檢測到失敗的手勢。iOS9加入)
sourceView:源視圖 (不懂,iOS9加入)
sourceRect:源視圖範圍 (iOS9加入)
方法:
- (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil;
實例化某個視圖控制器
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder;反歸檔
- (void)loadView;加載視圖,生命週期只有一次
- (void)loadViewIfNeeded;在視圖沒有加載成功的狀況下將視圖建立出來,並從新調用viewDidLoad方法 (iOS9加入)
- (void)viewWillUnload;視圖將會被卸載
- (void)viewDidUnload;視圖被卸載
- (void)viewDidLoad; 視圖加載完成 (通常在這個方法裏面定義UI控件,製備調用一次)
- (BOOL)isViewLoaded;判斷view是否被加載
- (void)performSegueWithIdentifier:(NSString *)identifier sender:(nullable id)sender;用於storyboard中的界面跳轉
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(nullable id)sender;是否可以觸發segue跳轉方式
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender;準備跳轉
- (BOOL)canPerformUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender;在UiViewController跳轉前調用,若是返回 NO則不跳轉
- (NSArray<UIViewController *> *)allowedChildViewControllersForUnwindingFromSource:(UIStoryboardUnwindSegueSource *)source;容許釋放子視圖控制器並放回全部的視圖控制器(iOS9加入)
- (nullable UIViewController *)childViewControllerContainingSegueSource:(UIStoryboardUnwindSegueSource *)source;子視圖控制器的segue源返回一個視圖控制器 (iOS 9 加入)
- (void)unwindForSegue:(UIStoryboardSegue *)unwindSegue towardsViewController:(UIViewController *)subsequentVC;自定義segue容器視圖控制器,用於跳轉 (iOS9加入)
- (void)viewWillAppear:(BOOL)animated;視圖將要顯示
- (void)viewDidAppear:(BOOL)animated; 視圖已經顯示
- (void)viewWillDisappear:(BOOL)animated;視圖將要消失
- (void)viewDidDisappear:(BOOL)animated;視圖已經消失
- (void)viewWillLayoutSubviews;在viewWillAppare後調用,將要對子視圖進行佈局
- (void)viewDidLayoutSubviews;已經佈局完成子視圖
- (void)didReceiveMemoryWarning; 內存警告
- (BOOL)isBeingPresented ; 是否容許開始跳轉
- (BOOL)isBeingDismissed ;是否容許開始消失
- (BOOL)isMovingToParentViewController ;是否移動到跳轉的視圖
- (BOOL)isMovingFromParentViewController ;是否從跳轉的時候中返回
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion ;界面跳轉(展示)
- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion 界面消失
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated;展示模態視圖控制器
- (void)dismissModalViewControllerAnimated:(BOOL)animated;退出模態視圖控制器
- (BOOL)disablesAutomaticKeyboardDismissal;在UIModalPresentationFormSheet風格下是否容許鍵盤隱藏
- (UIStatusBarStyle)preferredStatusBarStyle;狀態來顏色 (返回UIStatusBarStyleDefault在亮色的背景顏色下狀態欄顏色是暗色,返回UIStatusBarStyleLightContent在暗色的背景顏色下狀態欄顏色是亮色,iOS7加 入)
- (BOOL)prefersStatusBarHidden;是否可以隱藏狀態欄 (iOS7加入)
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation;狀態欄顯示或者隱藏動畫 (iOS7加入)
- (void)setNeedsStatusBarAppearanceUpdate;設置須要更新狀態欄 (iOS7加入)
- (nullable UIViewController *)targetViewControllerForAction:(SEL)action sender:(nullable id)sender;返回一個最近的先祖視圖控制器,用於先祖視圖控制器和本視圖控制器之間的傳值。 (ios 8 加入)
- (void)showViewController:(UIViewController *)vc sender:(nullable id)sender;顯示視圖併發送它的先祖 (iOS8加入)
- (void)showDetailViewController:(UIViewController *)vc sender:(nullable id)sender;顯示視圖控制器中的細節 (iOS8加入)
+ (void)attemptRotationToDeviceOrientation;讓interface orientation和device orientation的方向當即保持一致。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;單獨控制某個UIVewController的旋轉方向
- (BOOL)shouldAutorotate;是否自動轉屏
- (UIInterfaceOrientationMask)supportedInterfaceOrientations;返回值決定interface orienation的旋轉方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation ;設置viewController在present時首選的默認方向
- (nullable UIView *)rotatingHeaderView;查詢當前的導航視圖
- (nullable UIView *)rotatingFooterView;查詢當前的標籤視圖
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;應用界面將要旋轉的時候前會調用
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;應用界面旋轉以後調用
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;在旋轉過程當中制定旋轉結束後控件的位置大小
- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;在旋轉過程當中制定旋轉結束後控件的位置大小(發生在前半段)
- (void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;在前半段旋轉以後發生,作一些自定義的操做
- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration;在旋轉過程當中制定旋轉結束後控件的位置大小(發生在後半段)
- (void)setEditing:(BOOL)editing animated:(BOOL)animated; 從新設定editing或者done按鈕的外觀
- (UIBarButtonItem *)editButtonItem;自定義的view,做爲導航欄的edit或者done按鈕
- (void)addChildViewController:(UIViewController *)childController ;添加子視圖控制器
- (void) removeFromParentViewController;從父視圖控制器中刪除子視圖控制器
- (void)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion;不一樣的view放到不一樣的視圖控制器中同時設置視圖控制器切換的時候的過分時間,過分效果,國度動畫
- (void)beginAppearanceTransition:(BOOL)isAppearing animated:(BOOL)animated;視圖控制器開始出現轉變
- (void)endAppearanceTransition;轉變結束同時觸發相應的viewWillDisappear方法
- (nullable UIViewController *)childViewControllerForStatusBarStyle;子視圖控制器的狀態來風格 (iOS7加入)
- (nullable UIViewController *)childViewControllerForStatusBarHidden;子視圖控制器狀態欄隱藏和取消隱藏狀態 (iOS7加入)
- (void)setOverrideTraitCollection:(nullable UITraitCollection *)collection forChildViewController:(UIViewController *)childViewController;爲子控制器從新設置traintCollection的值 (通常用於自定義 controller,ios8加入)
- (nullable UITraitCollection *)overrideTraitCollectionForChildViewController:(UIViewController *)childViewController;獲取子控制器的trainCollection值
- (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers;能夠關閉appearance callbacks的自動傳遞特性(iOS5中)
- (BOOL)shouldAutomaticallyForwardRotationMethods;禁止旋轉回調自動傳遞的特性(iOS6中)
- (BOOL)shouldAutomaticallyForwardAppearanceMethods;在iOS6以後關閉appearance callbacks的自動傳遞特性
- (void)willMoveToParentViewController:(nullable UIViewController *)parent;存在父視圖控制器和子視圖控制器的時候父視圖控制器將要出現的時候調用
- (void)didMoveToParentViewController:(nullable UIViewController *)parent;在顯示ParentViewController以後自動調用
- (void) encodeRestorableStateWithCoder:(NSCoder *)coder;保存視圖狀態相關信息(歸檔)
- (void) decodeRestorableStateWithCoder:(NSCoder *)coder;恢復和保持視圖狀態相關信息
- (void) applicationFinishedRestoringState;其餘對象解碼完成後系統會自動調用此方法(iOS7加入)
- (void)updateViewConstraints ;更新佈局約束
- (void)addKeyCommand:(UIKeyCommand *)keyCommand;添加按鍵命令 (iOS9加入)
- (void)removeKeyCommand:(UIKeyCommand *)keyCommand;移除按鍵命令 (iOS9加入)
- (nullable UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location;預覽上下文視圖控制器的和視圖控制器所在的位置 (iOS9加 入)?
- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit ;添加視圖控制器並預覽 (iOS9加入)?
- (id <UIViewControllerPreviewing>)registerForPreviewingWithDelegate:(id<UIViewControllerPreviewingDelegate>)delegate sourceView:(UIView *)sourceView;
- (void)unregisterForPreviewingWithContext:(id <UIViewControllerPreviewing>)previewing;
- (NSArray <id <UIPreviewActionItem>> *)previewActionItems;預覽操做項 (ios9加入)
+ (instancetype)actionWithTitle:(NSString *)title style:(UIPreviewActionStyle)style handler:(void (^)(UIPreviewAction *action, UIViewController *previewViewController))handler;
+ (instancetype)actionGroupWithTitle:(NSString *)title style:(UIPreviewActionStyle)style actions:(NSArray<UIPreviewAction *> *)actions;