如何在iOS5中获取默认的LandscapeLeft方向?
对不起,如果这个问题是重复的,但我找不到相同的解决scheme。 在iOS6中,如果我想为一个UIViewController设置默认方向,我只需使用:
- (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskLandscapeLeft; }
但是如何在iOS5中做同样的事情,我testing了两个:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);//not default } and - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (toInterfaceOrientation == UIInterfaceOrientationMaskLandscapeLeft);// = return NO; }
但默认的方向总是肖像。任何build议?
调用下面的方法,你要检查orientation.happy编码的状态:-)
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [self CheckForViewForOrientation:toInterfaceOrientation]; } - (void) CheckForViewForOrientation:(UIInterfaceOrientation)orientation { if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { //Ur lable portrait view } else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { //Ur lable for landscape view } }
如果您想为整个应用程序实现此目的,请在app.plist文件中更改支持的方向UISupportedInterfaceOrientations
- (BOOL)shouldAutorotate { UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation]; if (orientation==UIInterfaceOrientationPortrait) { // do some } return YES; }
包括同时支持5和6的两种方法
你需要提供
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { UIInterfaceOrientationIsLandscape(interfaceOrientation); }
为那个单一的视图控制器。