2 回答

TA貢獻1796條經(jīng)驗 獲得超4個贊
弄清楚了。
1)子類化UINavigationController(層次結構的頂部viewcontroller將控制方向。)確實將其設置為self.window.rootViewController。
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
2)如果您不希望視圖控制器旋轉
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
3)如果您希望它能夠旋轉
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(BOOL)shouldAutorotate
{
return YES;
}
順便說一句,根據(jù)您的需要,另一種相關方法:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}

TA貢獻1829條經(jīng)驗 獲得超4個贊
如果您使用標簽欄控制器而不是導航控制器作為根控制器,則需要類似地將UITabBarController子類化。
語法也會有所不同。我成功地使用了以下內容。然后,我在要覆蓋的視圖控制器上成功使用了上面的示例。就我而言,我希望主屏幕不旋轉,但是我有一個帶有電影的FAQ屏幕,我自然想啟用橫向視圖。完美地工作!只需注意self.modalViewController的語法更改即可(如果嘗試將語法用于導航控制器,則會收到編譯器警告。)希望這會有所幫助!
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotate
{
return self.modalViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.modalViewController.supportedInterfaceOrientations;
}
- 2 回答
- 0 關注
- 602 瀏覽
添加回答
舉報