旋转到横向以查看视图 - iOS

时间:2014-10-29 05:50:25

标签: ios objective-c

我使用下面的代码强制视图横向显示。

objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft);

Apple是否会批准这个方向或有机会拒绝我的应用程序。请提供您的解决方案。

1 个答案:

答案 0 :(得分:0)

我不这么认为。 Apple documentation声明该方向是只读属性。

要强制横向进入ViewController,您可以执行以下操作:

- (NSUInteger)supportedInterfaceOrientations;
{
    return UIInterfaceOrientationMaskLandscape;
}

以指定的方向模式显示ViewController:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
{
    return UIInterfaceOrientationLandscapeLeft;
}

要实现所有这些,项目的plist必须支持方向并且:

- (BOOL)shouldAutorotate;
{
    return YES;
}

所有这些都假设视图控制器没有出现在同一个UINavigationController下。对于这种情况,您应参考有关在UINavigationController上强制轮换的讨论:UINavigationController Force Rotate

对于您想强制进入横向的视图,您始终可以使用transform:

self.view.transform = CGAffineTransformMakeRotation(M_PI/2.0);
相关问题