2 回答
TA贡献1911条经验 获得超7个赞
好的,我可以在iOS6 iPad Simulator中使用它。好极了。这是我所做的:
我只是告诉你之前和之后,这应该是不言而喻的:
之前
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation==UIInterfaceOrientationPortrait) {
// do some sh!t
}
return YES;
}
后
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation==UIInterfaceOrientationPortrait) {
// do some sh!t
}
return YES;
}
至于支持的方向,您可以在info.plist中这样指定:
或使用代码:
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait; // etc
}
编辑:再三考虑,如果您打算支持较低版本(iOS4.3 / 5 / 5.1)以及6.0,则只需包含两种具有相同代码内容的方法即可。为我工作(无论如何在SIM卡中)
TA贡献1835条经验 获得超7个赞
这是针对iOS 5和更早版本代码的解决方案,它不涉及重复逻辑。只需将此代码添加到您的视图控制器中,它就会从您现有的shouldAutorotateToInterfaceOrientation方法中生成supportedInterfaceOrientations。
-(BOOL)shouldAutorotate{
return YES;
}
-(NSInteger)supportedInterfaceOrientations{
NSInteger mask = 0;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight])
mask |= UIInterfaceOrientationMaskLandscapeRight;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeLeft])
mask |= UIInterfaceOrientationMaskLandscapeLeft;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortrait])
mask |= UIInterfaceOrientationMaskPortrait;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortraitUpsideDown])
mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
return mask;
}
- 2 回答
- 0 关注
- 697 浏览
添加回答
举报