很抱歉,如果这个问题是重复的,但我不能找到同样的解决方案。 在iOS6的,如果我想设置默认方向为一个的UIViewController,我只是用:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft;
}
但如何在iOS5中做的一样,我测试两个:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);//not default
}
and
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationMaskLandscapeLeft);// = return NO;
}
但是默认的方向总是Portrait.Any建议吗?
call the below method where you want to check the status of orientation.happy coding :-)
- (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
}
}
如果要达到这一目的的整个应用程序,支持改变方向UISupportedInterfaceOrientations在app.plist文件
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation==UIInterfaceOrientationPortrait) {
// do some
}
return YES;
}
包括同时支持5和6的方法
您需要提供
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
对于单一视图控制器。