Navigation bar title view missing in iOS11

2019-08-16 17:57发布

问题:

I'm working on a project in swift for iPad. Have placed an image view in Navigation bar title view from story board. The title view is displaying as expected in iOS 10 and below. The same project when i run in iOS 11 simulators and the physical devices Navigation bar is not showing the title view, any leads would be appreciated.

回答1:

Create a custom view and override below method in the custom title view class to update view frame size at runtime.

Obj-C

-(CGSize)intrinsicContentSize
{
    [super intrinsicContentSize];
    return UILayoutFittingExpandedSize;
}

Swift

override var intrinsicContentSize: CGSize {
    return UILayoutFittingExpandedSize
}

Check and let me know is it working for you or not ?



回答2:

Maybe this can help you

let widthConstraint = view.widthAnchor.constraint(equalToConstant: width)
let heightConstraint = view.heightAnchor.constraint(equalToConstant:height)
widthConstraint.isActive = true
heightConstraint.isActive = true

view is the view that you use as a custom title view. And width and height is the size that you want to use. You can use:

let width = view.frame.width
let height = view.frame.height