Ios6 iOS中的方向
我是新来的。我想知道如何在iOS中实现定向。现在,iOS5(及以下版本)和iOS6使用的方法都不同了 所有对象的框架是否应设置为4种不同的类型(纵向上下、纵向、横向左、横向右) 我试过了Ios6 iOS中的方向,ios6,frame,orientation-changes,ios5,Ios6,Frame,Orientation Changes,Ios5,我是新来的。我想知道如何在iOS中实现定向。现在,iOS5(及以下版本)和iOS6使用的方法都不同了 所有对象的框架是否应设置为4种不同的类型(纵向上下、纵向、横向左、横向右) 我试过了 -(BOOL)shouldAutoRotate { return YES; } 但它不起作用。你能说得更清楚些吗?是否允许某些视图更改方向,而不允许其他视图更改方向?如果希望在iOS6中允许所有旋转,只需在每个viewController中为下面的函数返回yes -(BOOL)shouldAutoRotate
-(BOOL)shouldAutoRotate
{
return YES;
}
但它不起作用。你能说得更清楚些吗?是否允许某些视图更改方向,而不允许其他视图更改方向?如果希望在iOS6中允许所有旋转,只需在每个viewController中为下面的函数返回yes
-(BOOL)shouldAutoRotate
{
return YES;
}
现在iOS6中不推荐使用shouldAutoRotateToInterfaceOrientation方法
此外,如果要在某个方向上锁定某些ViewController,请替代下面的方法
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;//whichever
}
如果希望在某些ViewController中允许方向更改,但在其他ViewController中不允许,则需要在每个基类和继承的类中重写这些方法。如果希望收到方向更改的通知,然后手动触发视图更改,您还可以选择使用NSNotificationCenter。如果你想知道如何做的细节,请告诉我
希望有帮助 这就是帮助我的代码。谢谢你的帮助
- (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.
}
我希望在所有控制器中允许定向。几天前我问了同样的问题。检查答案,对我有用。