我正在开发一款使用横向模式的游戏,总共有 4 个视图。横向模式下可以正确显示 2 个视图。但在第三个视图中我有 UITable 和导航栏。我可以在横向模式下旋转表格,但无法转换导航栏和导航控制器。导航栏和导航控制器上也有按钮。它也没有得到转变。那么任何人都可以解决这个问题。:)

有帮助吗?

解决方案

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

其他提示

#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];
}

在 UIViewController 文档的类中:

处理旋转

interfaceOrientation 属性
– shouldAutorotateToInterfaceOrientation:
– 旋转FooterView
– 旋转标题视图
– willRotateToInterfaceOrientation:持续时间:
– willAnimateFirstHalfOfRotationToInterfaceOrientation:持续时间:
– willAnimateSecondHalfOfRotationFromInterfaceOrientation:持续时间:
– didRotateFromInterfaceOrientation:

希望这对你也有帮助。

A。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top