当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - In iOS6, UIViewController's view position is wrong at app launch

问题描述:

IEverything works fine before iOS 6. I have a UIViewController subclass in a UINavigationController as usual. Its view is shrinking down about 20 px as if there is another status bar up top. When I push and pop the view back. The view went back to its correct position. I found out it's because UIViewControllerWrapperView (got by using self.view.superview) frame got wrong somehow in iOS 6.

Doing NSLog in viewDidAppear

At app launch ...

self.view.frame: {{0, 0}, {768, 891}} // was {{0, 0}, {768, 911}} in iOS5.1

self.view.superview: <UIViewControllerWrapperView: 0x9dddb80; frame = (0 20; 768 891); autoresize = W+H; layer = <CALayer: 0x9dddc30>>

// was (0 0; 768 911); in iOS5.1

After push and pop view controller (correct value) ...

self.view.frame: {{0, 0}, {768, 911}}

self.view.superview: <UIViewControllerWrapperView: 0x9dddb80; frame = (0 0; 768 911); autoresize = W+H; layer = <CALayer: 0x9dddc30>>

It never happens before. How does this appear in iOS 6 ?

网友答案:

Here is my current dirty fix in viewDidAppear.

// fix wrong UIViewControllerWrapperView frame by moving up and extending it back
CGRect wvFrame = self.view.superview.frame;
if (wvFrame.origin.y > 0) {
    wvFrame.size.height += wvFrame.origin.y;
    wvFrame.origin.y = 0;
    self.view.superview.frame = wvFrame;
}
网友答案:

There's a better fix than accepted. Try to set wantsFullScreenLayout to YES in viewDidLoad.

self.wantsFullScreenLayout = YES;
分享给朋友:
您可能感兴趣的文章:
随机阅读: