iOS中的方向

时间:2012-10-17 07:31:23

标签: ios6 frame orientation-changes ios5

我是新来的导演。我想知道如何在iOS中实现方向。现在使用的方法对于iOS5(及以下)和iOS6都不同。

是否应在4种类型中设置所有对象的框架(PortraitUpsideDown,Portrait,Landscape left,Landscape right)?

我试过

-(BOOL)shouldAutoRotate
{
return YES;
}

但它没有用。

2 个答案:

答案 0 :(得分:2)

这是帮助我的代码。谢谢你的帮助。

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     //Only iOS5 and below
     return YES;
}


- (BOOL)shouldAutorotate {
     //Only iOS6
     return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
     //Only iOS6
     return UIInterfaceOrientationMaskAll;

}


-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

     //iOS6 and below

     if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
          [self landscapeView];

     }
     else {
           [self portraitView];
    }   
}


-(void) portraitView {
//Set the portrait frames here.
}


-(void) landscapeView {
//Set the landscape frames here.
}

答案 1 :(得分:0)

你能说清楚吗?您是否希望允许某些视图的方向更改而不允许其他视图的方向更改?如果你想在iOS6中允许所有旋转,只需在每个viewController

中为下面的函数返回yes
-(BOOL)shouldAutoRotate
{
return YES;
}

现在,iOS6中不推荐使用shouldAutoRotateToInterfaceOrientation方法。

另外,如果要锁定某个方向的某些viewControllers,请覆盖下面的方法。

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;//whichever
}

如果要在某些viewControllers中允许方向更改,而在其他viewControllers中不允许,则需要在每个基类和继承的类中重写这些方法。如果要通知方向更改,然后手动触发视图更改,还可以选择使用NSNotificationCenter。如果您想了解具体方法,请告诉我。

希望它有所帮助!