[英]IOS6 rotation issue
我知道你必須為IOS6使用新的旋轉方法,但似乎我寫的方法不起作用。
我設置我的plist文件以允許所有旋轉但不允許portraitUpsideDown
然后我在appDelegate中有以下內容:
self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window setRootViewController:navController]; //add nav controller to be the root view
然后在我的rootView中,推送到另一個控制器,我有:
WebViewViewController *webController = [[JBWebViewViewController alloc] init];
webController.urlString = urlName;
[self.navigationController pushViewController:webController animated:YES];
在網絡控制器中,我有:
#pragma mark - System Rotation Methods
//for any version before 6.0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//only allow landscape
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
/for 6.0+
- (BOOL)shouldAutorotate{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
我想要做的是,在根視圖中允許3次旋轉,但是當切換到Web視圖時(注意我確實推導航,不添加子視圖),我只想允許縱向視圖。
請有人幫幫我
-------更新----------
我已經創建了自己的UINavigationController的navController子類,我有一個BOOL landscapeModeOn,我可以設置它來告訴自動旋轉規格
#pragma mark - System Rotation Methods
//for any version before 6.0
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
if (landscapeModeOn) {
return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
} else {
return interfaceOrientation == UIInterfaceOrientationPortrait;
}
}
//for 6.0+
- (NSUInteger)supportedInterfaceOrientations{
if (landscapeModeOn) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
return UIInterfaceOrientationMaskPortrait;
}
}
- (BOOL)shouldAutorotate{
UIInterfaceOrientation ori = [UIDevice currentDevice].orientation;
if (landscapeModeOn) {
return ori != UIInterfaceOrientationPortraitUpsideDown;
} else {
return ori == UIInterfaceOrientationPortrait;
}
}
在子視圖加載中,我做:
- (void)viewWillAppear:(BOOL)animated{
//get nav controller and turn off landscape mode
JBNavController *navController = (JBNavController*)self.navigationController;
[navController setLandscapeModeOn:NO];
[navController shouldAutorotate];
}
--------------------參考最佳答案的引用對於IOS6,蘋果現在專注於使用Storyboard的AutoLayout和新的旋轉定義,很難修復一些基於ios 4.3和ios 5編碼結構的IOS6微小錯誤
來自applefreak,他的建議暗示:
您的案例中的主要挑戰是不處理方向。 實際上,它將不同的視圖控制器鎖定到特定方向
雖然手動旋轉視圖似乎很難沒有任何錯誤,但它似乎是我現在嘗試的唯一解決方案,將發布更多一旦解決
根據您的情況,您必須為您的NavigationController創建子類,並將shouldAutorotate和supportedInterfaceOrientations方法添加到其中。 iOS6現在以與iOS5相反的順序詢問您的導航堆棧,因此它將首先詢問您的NavigationController,如果返回YES,它甚至不會咨詢它的子視圖控制器。 要解決此問題,您必須自己添加邏輯來執行此操作
因此,在您的子類導航控制器中,您手動詢問當前的viewcontroller它的自動旋轉能力:
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
在您的個人視圖控制器中,您現在可以實現這些功能,並讓它們返回您在問題中定義的所需值。
我希望這是有道理的。
以下代碼錯了!
- (BOOL)shouldAutorotate{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
請記住,僅當shouldAutoRotate返回YES時才會調用supportedInterfaceOrientations。 現在,根視圖控制器決定它的子節點是否旋轉。
在你的情況下,我建議你的self.viewController有一個基類控制器,並將self.viewController設置為root視圖控制器而不是navigationController,否則不會調用旋轉方法! 我遇到了同樣的問題。 您應該與基本視圖控制器及其子級具有HAS-A關系。 根據活動子項從ShouldAutoRotate返回是/否,對於支持的方向,返回相同。 如果您遵循這種架構,那么它對於復雜的應用程序將是一致的。
例如,在您的情況下,BaseviewController應該從shouldAutoRotate返回YES,並在webviewController處於活動狀態時從支持的方向委托返回UIInterfaceOrientationPortrait。 我希望這是有道理的。
它是iOS5和iOS6的通用代碼
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
// here to implement landscope code
}
else
{
// here to implement setframePortrait
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.