2 回答

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

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超4個贊
如果您使用標(biāo)簽欄控制器而不是導(dǎo)航控制器作為根控制器,則需要類似地將UITabBarController子類化。
語法也會有所不同。我成功地使用了以下內(nèi)容。然后,我在要覆蓋的視圖控制器上成功使用了上面的示例。就我而言,我希望主屏幕不旋轉(zhuǎn),但是我有一個帶有電影的FAQ屏幕,我自然想啟用橫向視圖。完美地工作!只需注意self.modalViewController的語法更改即可(如果嘗試將語法用于導(dǎo)航控制器,則會收到編譯器警告。)希望這會有所幫助!
- (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 關(guān)注
- 609 瀏覽
添加回答
舉報