UIViewController 基础篇

               UIViewController提供了一个基础的视图管理模型,可以用UIViewController管理视图的继承,及对view的管理。

               属性:

               view:视图  (UIViewController的一个属性,用于UI控件的存放和操作)

               viewIfLoaded:是否加载视图成功 (是一个只读属性,如果加载成功则返回视图控制器的视图,如果没有加载成功则返回空值。iOS9加入)

               nibName:nib视图的名字 (只读)

               nibBundle:nib视图的位置 (只读)

               storyboard:故事版 (只读)

               title:标题 (在父视图控制器上面使用效果和self.navigationItem.title一样)

               parentViewController:父视图控制器 (只读)

               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;

          

      

         

        


          

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值