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 關注
- 725 瀏覽
添加回答
舉報