如何在横向模式下转换导航栏和导航控制器

Jyo*_*sna 5 iphone cocoa-touch objective-c

我正在开发一个游戏,我正在使用横​​向模式,我有4个视图.2个视图正在以横向模式进入.但在第三个视图中我有UITable和导航栏.我可以在横向模式下旋转表,但无法转换导航栏和导航控制器.导航栏和导航控制器上也有Button.它也没有变形.所以任何人都可以解决这个问题.:)

mie*_*tus 7

#define degreesToRadians(x) (M_PI * x / 180.0)

- (void)viewWillAppear:(BOOL)animated
{

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

    CGRect newBounds = CGRectMake(0, 0, 480, 320);
    self.navigationController.view.bounds = newBounds;
    self.navigationController.view.center = CGPointMake(newBounds.size.height / 2.0, newBounds.size.width / 2.0);

    self.navigationController.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));

    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.view.transform = CGAffineTransformIdentity;
    self.navigationController.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
    self.navigationController.view.bounds = CGRectMake(0.0, 0.0, 320.0, 480.0);

    [super viewWillDisappear:animated];
}
Run Code Online (Sandbox Code Playgroud)


Sne*_*hal 2

通过旋转 90 度来变换导航控制器的导航栏。此外,您可能需要设置导航栏中心和框架,以设置适当的宽度以适应横向模式。它对我有用:)希望它也对您有帮助。