我在iOS 6 SDK中遇到了这个问题:我有一些应该被允许轮换的视图(例如视频视图),而有些则不允许.现在我明白我必须检查应用程序的Info.plist中的所有方向,然后在每个ViewController中进行排序,应该发生什么.但它不起作用!应用程序始终旋转到Info.plist中给出的方向.
Info.plist的:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Run Code Online (Sandbox Code Playgroud)
任何不允许旋转的ViewController:
//deprecated
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
观察:App旋转到横向和纵向.任何想法为什么或我做错了什么?
干杯,马克
编辑:我的最新调查结果还表明,如果您希望在应用程序中的某个位置进行旋转,则必须激活项目设置或Info.plist中的所有四个旋转方向.替代方法是覆盖
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
Run Code Online (Sandbox Code Playgroud)
在你的AppDelegate中,它会覆盖Info.plist.不再可能只在Info.plist中设置Portrait,然后通过覆盖shouldAutorotateToInterfaceOrientation或supportedInterfaceOrientations在某些ViewController中进行旋转.
我有UIViewController以下代码:
- (BOOL) shouldAutorotate {
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
Run Code Online (Sandbox Code Playgroud)
我没有使用UINavigationController.当这个UIViewController被显示,该装置仍将旋转为横向.我的目标是iOS 9,这里的问题是什么?
我正在使用ARKit,我想允许用户在纵向和横向模式下使用该应用程序.我希望所有UI控件在方向更改时旋转,除了ARSCNView.我试图在相反的方向转换sceneView但是没有用.
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
let targetRotation = coordinator.targetTransform
let inverseRotation = targetRotation.inverted()
coordinator.animate(alongsideTransition: { (context) in
self.sceneView.transform = self.sceneView.transform.concatenating(inverseRotation)
context.viewController(forKey: UITransitionContextViewControllerKey.from)
}, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
如何防止ARKit会话的场景视图旋转,同时允许所有其他UI控件在方向更改时旋转?