屏幕旋转时,UINavigationBar的旋转问题

以UINavigationController为根视图,在UINavigationController的子类中做如下重写

#import "MyNavigationViewController.h"

@interface MyNavigationViewController ()

@end

@implementation MyNavigationViewController

-(BOOL)shouldAutorotate {
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations {
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

@end


A画面中可以做任何旋转操作设置代码如下:

// 画面の回転制御
- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}


在A画面在横屏的状态下push出B画面,B画面做如下设置

// 画面の回転制御
- (void)viewWillAppear:(BOOL)animated
{
    self.view.transform = CGAffineTransformIdentity;
    
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

    
    CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;//(获取当前电池条动画改变的时间)
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:duration];
    
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
    
    if (orientation == UIInterfaceOrientationLandscapeLeft) {
        
        
        self.view.transform = CGAffineTransformMakeRotation(M_PI);
        
        
    } else if (orientation == UIInterfaceOrientationLandscapeRight) {
        

        self.view.transform = CGAffineTransformMakeRotation(-M_PI_2);
        
    } else {
        

        self.view.transform = CGAffineTransformIdentity;
        
    }
    
     [UIView commitAnimations];

}



-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}


此时B画面显示时,屏幕转为竖屏,但是问题是UINavigationBar依然保持着在A画面的位置,竖在屏幕上。请问这种问题怎么解决。看了好多网上写的解决办法。说是好用但是我这都没有效果,是我哪个地方设置的有问题么。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值