您的位置:首页 > 产品设计 > UI/UE

IOS8 UIViewcontroller API使用说明

2014-12-25 10:20 369 查看
1、UIViewControllerIn 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 the
viewWillTransitionToSize: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 [code]UITabBarController
.
View controllers set as the root view controller do not react to this property. Default value is
UIRectEdgeAll
.[/code]
@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:
约束示例:
[buttonsetTranslatesAutoresizingMaskIntoConstraints:
NO];
idbottomGuide
=
myViewController.bottomLayoutGuide;
NSDictionary*viewsDictionary=
NSDictionaryOfVariableBindings
(button,bottomGuide);
[myViewController.viewaddConstraints:
[NSLayoutConstraintconstraintsWithVisualFormat:
@"V: [button]-20-[bottomGuide]"
options:0
metrics:nil
views:viewsDictionary]];
[self.viewlayoutSubviews];// You must call this method here or the system raises an exception
获取高度
-(void)viewDidLayoutSubviews
{
CGRectviewBounds
=
self.view.bounds;
CGFloatbottomBarOffset
=
self.bottomLayoutGuide.length;
}
In the case of using a view subclass, obtain the numbers you need as follows:
-(void)layoutSubviews
{
[superlayoutSubviews];// You must call super here or the system raises an exception
CGRectbounds
=
self.bounds;
CGFloatbottomBarOffset
=
myVCReference.bottomLayoutGuide.length;
}
@property(nonatomic, readonly, retain) id< UILayoutSupport >topLayoutGuideAs 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:
[buttonsetTranslatesAutoresizingMaskIntoConstraints:
NO];
idtopGuide
=
myViewController.topLayoutGuide;
NSDictionary*viewsDictionary=
NSDictionaryOfVariableBindings
(button,topGuide);
[myViewController.viewaddConstraints:
[NSLayoutConstraintconstraintsWithVisualFormat:
@"V: [topGuide]-20-[button]"
options:0
metrics:nil
views:viewsDictionary]];
[self.viewlayoutSubviews];// 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 the
splitViewController: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 the
splitViewController: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
[code]extensionContext
value.[/code]
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:
or
showDetailViewController: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.

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: