iOS 7 UIToolBar Overriding With Status Bar

前端 未结 6 1439
你的背包
你的背包 2020-12-06 07:20

I have upgraded my project from iOS 6 to iOS 7 but there seems a little problem. The status bar and a tool bar is overriding and very close to each other. The tool bar was e

相关标签:
6条回答
  • 2020-12-06 07:41

    If your setup is a split view like setup with two container views, you should be able to do this. When you set up the container views, drag the top up until you see the dotted blue line that indicates the top is at the bottom of the status bar. Do this with both container views. Add the tool bar to the embedded controller (not the container view), pinned to the top of that controller's view. With the left view being embedded in a navigation controller, my screen looked like this:

    enter image description here

    0 讨论(0)
  • 2020-12-06 07:42

    Your view's top constraint should no longer be top space to superview, but rather top space top top layout guide.

    You can do this by moving the top space down beneath the status bar and then using the constraint menu to add the constraint to the nearest neighbor, which should now be the top layout guide, or you can do it as describe in this link on apple's developer library.

    0 讨论(0)
  • 2020-12-06 07:42

    Swift 3

    Connect your bar delegate and conform to UIToolbarDelegate. Then add this delegate method:

    func position(for bar: UIBarPositioning) -> UIBarPosition {
        return UIBarPosition.topAttached
    }
    

    because now

    enum UIBarPosition : Int {
        case any
        case bottom
        case top
        case topAttached
    }
    
    0 讨论(0)
  • 2020-12-06 07:55
    _toolBar.delegate = self;
    
    - (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar {
        CGRect frame = _toolBar.frame;
        frame.origin = CGPointMake(0, [UIApplication sharedApplication].statusBarFrame.size.height);
        _toolBar.frame = frame;
    
        return UIBarPositionTopAttached;
    }
    

    portrait bar

    landscape bar

    0 讨论(0)
  • 2020-12-06 07:57

    I was trying to do pretty much the same thing, but I didn't like the white status bar of the accepted answer. I managed to make the toolbar placed underneath the status bar so that it has a consistent color to the Navigation Bar that is next to it in the Master view.

    My solution was to make the Toolbar 64 points tall and set the Topspace to the superview to 0.

    When doing this you have to make sure you are not creating the constraint to the Top Space Layout Guide. I was able to get that done in Interface Builder by setting the Frame to 0,0 with a Height of 64. Then I used the Pin dialog off of the floating tool menu. I used zero with the top I beam to create the constraint.

    The bottom edges match in the Master and Detail and the coloring is consistent. The controls in my toolbar ended up uncrowded.

    0 讨论(0)
  • 2020-12-06 07:58

    Remember that you shouldn't just move things down in IB for two reasons:

    1. Not compatible with iOS 6
    2. Won't extend the top bar background effect under the status bar

    What not to do...

    So, if you want to iOS6 & iOS7 compatibility, you could add a conditional for objects that require customization in ViewDidLoad. Caveat being this is a last case scenario - always try to remedy it with autolayout / IB first:

    #import <Availability.h>
    
    #ifdef __IPHONE_7_0
    
            CGRect barFrame = topBar.frame;
            barFrame.origin = CGPointMake(0, [UIApplication sharedApplication].statusBarFrame.size.height);
            [topBar setFrame:barFrame];
    
            // move other stuff around too
    
        #endif
    

    And set your bar delegate much like Luniz above,override positionForBar to .

    topBar.delegate = self;
    
    - (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar {
    
        return UIBarPositionTopAttached;
    }
    
    0 讨论(0)
提交回复
热议问题