3 回答

TA貢獻1802條經驗 獲得超6個贊
簡單,但效果很好。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貢獻1712條經驗 獲得超3個贊
您的視圖控制器將永遠不會旋轉到應用程序本身不支持的任何位置。您應該啟用所有可能的旋轉,然后在不應旋轉的視圖控制器中放入以下行
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
在ChatView中,應為:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
如果您需要在輪換之后更改布局,則應對子視圖進行適當的更改
- (void)viewWillLayoutSubviews
使用self.view.bounds檢查的電流的大小view,因為self.view.frame旋轉后也不會改變。
- 3 回答
- 0 關注
- 529 瀏覽
添加回答
舉報