3 回答

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超10個(gè)贊
簡單,但效果很好。iOS 7.1和8
AppDelegate.h
@property () BOOL restrictRotation;
AppDelegate.m
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(self.restrictRotation)
return UIInterfaceOrientationMaskPortrait;
else
return UIInterfaceOrientationMaskAll;
}
ViewController
-(void) restrictRotation:(BOOL) restriction
{
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate.restrictRotation = restriction;
}
viewDidLoad
[self restrictRotation:YES]; or NO

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個(gè)贊
您的視圖控制器將永遠(yuǎn)不會(huì)旋轉(zhuǎn)到應(yīng)用程序本身不支持的任何位置。您應(yīng)該啟用所有可能的旋轉(zhuǎn),然后在不應(yīng)旋轉(zhuǎn)的視圖控制器中放入以下行
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
在ChatView中,應(yīng)為:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
如果您需要在輪換之后更改布局,則應(yīng)對子視圖進(jìn)行適當(dāng)?shù)母?/p>
- (void)viewWillLayoutSubviews
使用self.view.bounds檢查的電流的大小view,因?yàn)閟elf.view.frame旋轉(zhuǎn)后也不會(huì)改變。
- 3 回答
- 0 關(guān)注
- 922 瀏覽
添加回答
舉報(bào)