IOS8 UIViewcontroller API使用说明

1、UIViewController

In iOS 8, all rotation-related methods are deprecated. Instead, rotations are treated as a change in the size of the view controller’s view and are therefore reported using theviewWillTransitionToSize:withTransitionCoordinator: method. When the interface orientation changes, UIKit calls this method on the window’s root view controller. That view controller then notifies its child view controllers, propagating the message throughout the view controller hierarchy.

在iOS中8,所有与旋转相关的方法已过时或被弃用。取而代之,旋转将被视为在视图控制器的视图的大小的变化,并因此报告使用viewWillTransitionToSize:withTransitionCoordinator:方法。当界面的方向发生变化,UIKit会调用窗口的根视图控制器上此方法。该视图控制器然后通知其子视图控制器,在整个视图控制器层次传播消息。

In iOS 6 and iOS 7, your app supports the interface orientations defined in your app’s Info.plist file. A view controller can override the supportedInterfaceOrientations method to limit the list of supported orientations. Typically, the system calls this method only on the root view controller of the window or a view controller presented to fill the entire screen; child view controllers use the portion of the window provided for them by their parent view controller and no longer participate directly in decisions about what rotations are supported. The intersection of the app'€™s orientation mask and the view controller'€™s orientation mask is used to determine which orientations a view controller can be rotated into.

在iOS6和iOS7系统,您的应用程序支持通过Info.plist文件来定义界面可旋转的方向。视图控制器也可以通过实现supportedInterfaceOrientations方法来限制支持方向的列表。典型地,调用此方法只对该本类控制器有效;对子类或者其他控制器无效。

When a rotation occurs for a visible view controller, the willRotateToInterfaceOrientation:duration:,willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation:methods are called during the rotation. The viewWillLayoutSubviews method is also called after the view is resized and positioned by its parent. If a view controller is not visible when an orientation change occurs, then the rotation methods are never called. However, the viewWillLayoutSubviews method is called when the view becomes visible. Your implementation of this method can call the statusBarOrientation method to determine the device orientation.

当旋转事件发生在一个可见的视图控制器上面时,该willRotateToInterfaceOrientation:duration:willAnimateRotationToInterfaceOrientation:duration:didRotateFromInterfaceOrientation:方法是在旋转过程中被调用。该viewWillLayoutSubviews方法在视图的大小和位置由其父之后也被调用。如果一个视图控制器是不可见的,当一个方向发生变化,那么旋转方法不会被调用。但是,当视点变得可见时viewWillLayoutSubviews方法会被调用。实现viewWillLayoutSubviews方法可以调用statusBarOrientation方法来确定设备方向。



推出另一个视图控制器样式

typedefenum{  

UIModalPresentationFullScreen=0,  

UIModalPresentationPageSheet,  

UIModalPresentationFormSheet,  

UIModalPresentationCurrentContext, 

UIModalPresentationCustom,  

UIModalPresentationOverFullScreen,  

UIModalPresentationOverCurrentContext,  

UIModalPresentationPopover,  

UIModalPresentationNone=-1

}UIModalPresentationStyle;


过渡模式样式

typedefenum{  

UIModalTransitionStyleCoverVertical=0,UIModalTransitionStyleFlipHorizontal,  

UIModalTransitionStyleCrossDissolve,  

UIModalTransitionStylePartialCurl,

}UIModalTransitionStyle;


- (void)updateViewConstraints 修改视图约束条件

You may override this method in a subclass in order to add constraints to the view or its subviews. If you override this method, your implementation must invoke super’s implementation.

@property(nonatomic, assign) BOOLautomaticallyAdjustsScrollViewInsets 滑动视图自动修正inset偏移量 Default value is YES


@property(nonatomic) CGSize preferredContentSize 优先设置内容大小

The value in this property is used primarily when displaying the view controller’s content in a popover but may also be used in other situations. Changing the value of this property while the view controller is being displayed in a popover animates the size change; however, the change is not animated if you specify a width or height of 0.0.


@property(nonatomic, assign) UIRectEdge edgesForExtendedLayout

This property is only applied to view controllers that are embedded in containers, such as UINavigationController or UITabBarController. View controllers set as the root view controller do not react to this property. Default value is UIRectEdgeAll.


@property(nonatomic, readonly, retain) id< UILayoutSupport >bottomLayoutGuide

As an example of how to programmatically use this property with Auto Layout, say you want to position a control such that its bottom edge is 20 points above the bottom layout guide. This scenario applies to any of the scenarios listed above. Use code similar to the following:

约束示例:

  • [button setTranslatesAutoresizingMaskIntoConstraints: NO];
  • id bottomGuide = myViewController.bottomLayoutGuide;
  • NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (button, bottomGuide);
  • [myViewController.view addConstraints:
  • [NSLayoutConstraint constraintsWithVisualFormat: @"V: [button]-20-[bottomGuide]"
  • options: 0
  • metrics: nil
  • views: viewsDictionary]];
  • [self.view layoutSubviews]; // You must call this method here or the system raises an exception

获取高度
  • - (void) viewDidLayoutSubviews {
  • CGRect viewBounds = self.view.bounds;
  • CGFloat bottomBarOffset = self.bottomLayoutGuide.length;
  • }
  • In the case of using a view subclass, obtain the numbers you need as follows:

    • - (void) layoutSubviews {
    • [super layoutSubviews]; // You must call super here or the system raises an exception
    • CGRect bounds = self.bounds;
    • CGFloat bottomBarOffset = myVCReference.bottomLayoutGuide.length;
    • }

@property ( nonatomic ,   readonly ,   retain )   id <   UILayoutSupport  > topLayoutGuide

As an example of how to programmatically use this property with Auto Layout, say you want to position a control such that its top edge is 20 points below the top layout guide. This scenario applies to any of the scenarios listed above. Use code similar to the following:

  • [button setTranslatesAutoresizingMaskIntoConstraints: NO];
  • id topGuide = myViewController.topLayoutGuide;
  • NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (button, topGuide);
  • [myViewController.view addConstraints:
  • [NSLayoutConstraint constraintsWithVisualFormat: @"V: [topGuide]-20-[button]"
  • options: 0
  • metrics: nil
  • views: viewsDictionary]];
  • [self.view layoutSubviews]; // You must call this method here or the system raises an exception

- ( void ) collapseSecondaryViewController: ( UIViewController * ) secondaryViewController
                 forSplitViewController: ( UISplitViewController * ) splitViewController  
This method provides default behavior when you do not overwrite thesplitViewController:collapseSecondaryViewController:ontoPrimaryViewController: method. The primary view controller associated with the split view controller is displayed.
Available in iOS 8.0 and later.

- (UIViewController *)separateSecondaryViewControllerForSplitViewController:(UISplitViewController *)splitViewController  

This method provides default behavior when you do not overwrite thesplitViewController:separateSecondaryViewControllerFromPrimaryViewController: method. The previous secondary view controller is returned.

Available in iOS 8.0 and later.


@property(nonatomic, readonly, retain) NSExtensionContext*extensionContext

The view controller can check this property to see if it participates in an extension request. If no extension context is set for the current view controller, the system walks up the view controller hierarchy to find a parent view controller that has a non nil extensionContext value.

Available in iOS 8.0 and later.


NSString *const UIViewControllerShowDetailTargetDidChangeNotification

UIViewControllerShowDetailTargetDidChangeNotification

This notification is sent when a split view controller is expanded or collapsed.

When a view controller is using showViewController:sender: orshowDetailViewController:sender:, it may need to know when a split view controller higher in the view hierarchy has changed.UIViewControllerShowDetailTargetDidChangeNotification is sent when a split view controller expands or collapses. The object of this notification is the view controller that caused the change.

Available in iOS 8.0 and later.





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值