iOS7 Custom ViewController transition and Top Layout Guide

后端 未结 4 1578
-上瘾入骨i
-上瘾入骨i 2021-02-01 04:32

I implemented a custom UIViewController Transition in my App, which replaces the navigation controllers built in push animation.

Everything works so far, except the topl

相关标签:
4条回答
  • 2021-02-01 05:03

    I ran into the exact same problem. My custom navigation controller's container view didn't have constraints. The minute I added vertical spacing constraints from the container view to its superview's layout guides (albeit the two were identical in size), and set the top/bottom/status bar appearance on the container view everything was ok and the layout guides of the pushed controllers were in the correct position. Hope that helps.

    Update: From the official documentation on topLayoutGuide

    A view controller within a container view controller does not set this property's value. Instead, the container view controller constrains the value to indicate: The bottom of the navigation bar, if a navigation bar is visible The bottom of the status bar, if only a status bar is visible The top edge of the view controller’s view, if neither a status bar nor navigation bar is visible

    So the container view needs to implement correct constraints and hide/show bars and such for the effects to work. AFAIK there is no API to do this in custom container view controllers.

    0 讨论(0)
  • 2021-02-01 05:06

    I was having an issue where the bottomLayoutGuide property would set itself to zero length and then would cause my buttons above the tab bar to fall below to tab bar with the autolayout.

    Have you looked at doing this

    [self.navigationController.view setNeedsLayout]
    

    I put it into my viewwillappear and I stopped getting a zero length on the bottomLayoutGuide property. Maybe that would help you out with your topLayoutGuide property too.

    0 讨论(0)
  • 2021-02-01 05:17

    I was able to work around this, with the following view hierarchy:

    UIView
     UIScrollView
      <content, constrained to UIScrollView>
    

    Constrain the UIScrollView to match the UIView's top, leading, trailing, and bottom edges. Interface Builder might want you to use the topLayoutGuide and bottomLayoutGuide for the UIScrollView, or it might not. Maybe it's dependent on the version of Xcode, but some of our View Controllers used the superview, others used the layout guides.

    For the views where Interface Builder didn't want to constraint the scroll view relative to its superview, I opened the storyboard in a text editor and adjusted the constraints on the scroll view by hand.

    Finally, on the View Controller, make sure that extend edges under top bar is YES, and so is Adjust Scroll View Insets.

    Basically, I'm avoiding using the topLayoutGuide, and instead relying on the scroll view insets, which does work.

    Where I didn't have a UIScrollView in the hierarchy, like you, NOT extending edges under the top bar worked for me.

    0 讨论(0)
  • 2021-02-01 05:21

    I found a way. First uncheck "Extend Edges" property of controller after that navigation bar will get in dark color. Add a view to controller and set top and bottom LayoutConstraint -100. Then make view's clipsubview property no (for navigaionbar transculent effect). My english is bad sorry for that. :)

    0 讨论(0)
提交回复
热议问题