【发布时间】:2014-12-24 18:08:33
【问题描述】:
我已使用以下代码强制视图为横向。
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft);
苹果是否批准这个定位或有机会拒绝我的应用程序。请提供您的解决方案。
【问题讨论】:
标签: ios objective-c
我已使用以下代码强制视图为横向。
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft);
苹果是否批准这个定位或有机会拒绝我的应用程序。请提供您的解决方案。
【问题讨论】:
标签: ios objective-c
我不这么认为。 Apple documentation 声明方向是只读属性。
要强制横向进入 ViewController,你可以这样做:
- (NSUInteger)supportedInterfaceOrientations;
{
return UIInterfaceOrientationMaskLandscape;
}
以指定的方向模式呈现 ViewController:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
{
return UIInterfaceOrientationLandscapeLeft;
}
为了实现所有这些,项目的 plist 必须支持方向和:
- (BOOL)shouldAutorotate;
{
return YES;
}
所有这些都是假设视图控制器不在同一个 UINavigationController 下呈现。对于这种情况,你应该参考这个关于在 UINavigationController 上强制旋转的讨论:UINavigationController Force Rotate
对于您想要强制为横向的视图,您始终可以使用变换:
self.view.transform = CGAffineTransformMakeRotation(M_PI/2.0);
【讨论】: