美文网首页
ios 7特性

ios 7特性

作者: ClarkWang_001 | 来源:发表于2015-07-01 07:00 被阅读104次

    Starting in iOS7, the view controllers use full-screen layout by default. At the same time, you have more control over how it lays out its views, and that's done with those properties:
    edgesForExtendedLayout
    Basically, with this property you set which sides of your view can be extended to cover the whole screen. Imagine that you push a UIViewController
    into a UINavigationController
    , when the view of that view controller is laid out, it will start where the navigation bar ends, but this property will set which sides of the view (top, left, right, bottom) can be extended to fill the whole screen.
    Let see it with an example:

    UIViewController *viewController = [[UIViewController alloc] init];
    viewController.view.backgroundColor = [UIColor redColor];
    UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    

    Here you are not setting the value of edgesForExtendedLayout, therefore the default value is taken (UIRectEdgeAll), so the view extends its layout to fill the whole screen.
    This is the result:


    enter image description hereenter image description here

    As you can see, the red background extends behind the navigation bar and the status bar.
    Now, you are going to set that value to UIRectEdgeNone, so you are telling the view controller to not extend the view to cover the screen:

    UIViewController *viewController = [[UIViewController alloc] init];
    viewController.view.backgroundColor = [UIColor redColor];
    viewController.edgesForExtendedLayout = UIRectEdgeNone;
    UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    

    And the result:

    enter image description hereenter image description here
    automaticallyAdjustsScrollViewInsets
    This property is used when your view is a UIScrollView
    or similar, like a UITableView
    . You want your table to start where the navigation bar ends, because you wont see the whole content if not, but at the same time you want your table to cover the whole screen when scrolling. In that case, setting edgesForExtendedLayout to None won't work because your table will start scrolling where the navigation bar ends and it wont go behind it.
    Here is where this property comes handy, if you let the view controller automatically adjust the insents (setting this property to YES, also the default value) it will add inset to the top of the table, so the table will start where the navigation bar ends, but the scroll will cover the whole screen.
    This is when is set to NO:
    enter image description hereenter image description here
    And YES (by default):
    enter image description hereenter image description here
    In both cases, the table scrolls behind the navigation bar, but in the second case (YES), it will start from below the navigation bar.
    extendedLayoutIncludesOpaqueBars
    This value is just an addition to the previous ones. If the status bar is opaque, the views won't be extended to include the status bar too, unless this parameter is YES.
    So, if you extend your view to cover the navigation bar (edgesForExtendedLayout to UIRectEdgeAll) and the parameter is NO (default) it wont cover the status bar if it's opaque.
    If something is not clear, write a comment and I'll answer to it.
    ** How iOS knows what UIScrollView to use? ** iOS grabs the first subview in your viewcontroller's view, so the one at index 0, and if it's a subclass of UIScrollView then applies the explained properties to it.
    Of course, this means that UITableViewController works by default (since the TableView is the first view).

    iOS 7 brings several changes to how you layout and customize the appearance of your UI. The changes in view-controller layout, tint color, and font affect all the UIKit objects in your app. In addition, enhancements to gesture recognizer APIs give you finer grained control over gesture interactions.

    • Using View Controllers

    In iOS 7, view controllers use full-screen layout. At the same time, iOS 7 gives you more granular control over the way a view controller lays out its views. In particular, the concept of full-screen layout has been refined to let a view controller specify the layout of each edge of its view.

    The wantsFullScreenLayout view controller property is deprecated in iOS 7. If you currently specify wantsFullScreenLayout = NO, the view controller may display its content at an unexpected screen location when it runs in iOS 7.

    To adjust how a view controller lays out its views, UIViewController provides the following properties:

    • edgesForExtendedLayout
      The edgesForExtendedLayout property uses the UIRectEdge type, which specifies each of a rectangle’s four edges, in addition to specifying none and all. Use edgesForExtendedLayout to specify which edges of a view should be extended, regardless of bar translucency. By default, the value of this property is UIRectEdgeAll.

    • extendedLayoutIncludesOpaqueBars
      If your design uses opaque bars, refine edgesForExtendedLayout by also setting the extendedLayoutIncludesOpaqueBars property to NO. (The default value of extendedLayoutIncludesOpaqueBars is NO.)

    • automaticallyAdjustsScrollViewInsets
      If you don’t want a scroll view’s content insets to be automatically adjusted, set automaticallyAdjustsScrollViewInsets to NO. (The default value of automaticallyAdjustsScrollViewInsets is YES.)

    • topLayoutGuide, bottomLayoutGuide
      The topLayoutGuide and bottomLayoutGuide properties indicate the location of the top or bottom bar edges in a view controller’s view. If bars should overlap the top or bottom of a view, you can use Interface Builder to position the view relative to the bar by creating constraints to the bottom of topLayoutGuide or to the top of bottomLayoutGuide. (If no bars should overlap the view, the bottom of topLayoutGuide is the same as the top of the view and the top of bottomLayoutGuide is the same as the bottom of the view.) Both properties are lazily created when requested.

    http://stackoverflow.com/questions/18798792/explaining-difference-between-automaticallyadjustsscrollviewinsets-extendedlayo

    http://stackoverflow.com/questions/17074365/status-bar-and-navigation-bar-appear-over-my-views-bounds-in-ios-7/18785646#18785646

    相关文章

      网友评论

          本文标题:ios 7特性

          本文链接:https://www.haomeiwen.com/subject/omneqttx.html