开发者

landscape mode problem with a navigation bar

I have a ViewController that manages a view in which I have a Table View, an ImageView and a Navigation Bar. When I put it in the landscape mode the Navigation Bar doesn't resize to 32, it still remains to 44 I tried first to use the autosizing in IB without success, then I tried to put this code in the ViewController

- (void)willAnim开发者_如何学运维ateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
    //[super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
    CGRect frame = self.navigationController.navigationBar.frame;
    if (UIInterfaceOrientationIsPortrait(orientation)) {
         frame.size.height = 44;
    } else {
         frame.size.height = 32;
    }
    self.navigationController.navigationBar.frame = frame;
}

but nothing. How can I solve this issue?


I made a mistake, there isn't a navigationController, so I linked the navigation bar in IB with the outlet navBar in the code and I've used

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation  duration:(NSTimeInterval)duration {
    [super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
    CGRect frame = self.navBar.frame;
    if (UIInterfaceOrientationIsPortrait(orientation)) {
        frame.size.height = 44;
    } else {
        frame.size.height = 32;
    }
    self.navBar.frame = frame;  
}

It works now, I've only a problem with the image view


I had the same problem with a customized background image for the navigation top bar.

My landscape image was not the correct height, it was 44px high instead of 32px (same for the @2x version, it was 88px instead of 64). After cropping the images, the landscape top bar has the correct height.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜