Xcode IOS锁一些方向肖像和一些风景
我正在研究有大约12个视图的应用程序。我希望有些人只是肖像而其他人是风景画。Xcode IOS锁一些方向肖像和一些风景
我该如何去锁定一些视图的方向到肖像和其他景观?
我试着从前面的例子下面的代码,但它不锁定方向。
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft]
forKey:@"orientation"];
近24个小时的努力后,我终于解决了这一问题。对于一个“ShouldAutoRotate”永远不会被调用。这就是我所能找到的所有地方“只需添加shouldAutoRotate”......没有工作。另外我不确定为什么人们会投我的问题。
我的工作是将下面的方法添加到我的Appdelegate.m文件。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;
if(self.window.rootViewController){
UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presentedViewController supportedInterfaceOrientations];
}
return orientations;
}
然后将下面的方法添加到viewcontroller.m文件我想锁定到横向。
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
你必须在你的ViewController中实现supportedInterfaceOrientation
和shouldAutorotate
。
LucaD您好, 加入 - (NSUInteger)supportedInterfaceOrientations和或 - (BOOL)shouldAutorotate。视图仍然旋转。 取自范例http://chrisrisner.com/31-Days-of-iOS--Day-16%E2%80%93Handling-Device-Orientation – Mich 2014-12-01 20:46:46
如果您在构建设置中启用其他界面方向,shouldAutoRotate应该可以工作。 – 2015-02-06 08:15:35
完美答案.... – 2015-11-02 13:12:39