2011-02-14 105 views
6

我使用willRotateToInterfaceOrientation在iPad旋轉時交換視圖。如果我的設備旋轉並交換視圖時打開了模式視圖或警報視圖,則即使警報稍後再次「呈現」,視圖也會交換並且警報消失並且不會再次出現。在iPad上旋轉時,如何阻止模態視圖消失?

編輯: 我已經縮小了這個問題。當模態視圖與UIModalPresentationFullScreen一起呈現時,模態視圖「存活」旋轉。

我能做些什麼來解決這個問題?

這是我實現的willRotateToInterfaceOrientation

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 

[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

// 
// Load an alternate view depending on the orientation 
// 


if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) { 

    [UIView beginAnimations:@"" context:nil]; 
    [self setView:theLandscapeView]; 
    self.view.bounds = CGRectMake(0, 0, 1024, 768); 
    self.view.transform = CGAffineTransformMakeRotation(kDegreesToRadians * (-90)); 
    [UIView commitAnimations];  

}else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { 

    [UIView beginAnimations:@"" context:nil]; 
    [self setView:theLandscapeView]; 
    self.view.bounds = CGRectMake(0, 0, 1024, 768); 
    self.view.transform = CGAffineTransformMakeRotation(kDegreesToRadians * (90)); 
    [UIView commitAnimations]; 

}else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { 

    [UIView beginAnimations:@"" context:nil]; 
    [self setView:thePortraitView]; 
    self.view.transform = CGAffineTransformMakeRotation(kDegreesToRadians * (0)); 
    self.view.bounds = CGRectMake(0, 0, 768, 1024); 
    [UIView commitAnimations]; 

}else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { 

    [UIView beginAnimations:@"" context:nil]; 
    [self setView:thePortraitView]; 
    self.view.transform = CGAffineTransformMakeRotation(kDegreesToRadians * (180)); 
    self.view.bounds = CGRectMake(0, 0, 768, 1024); 
    [UIView commitAnimations]; 
} 
} 
+0

謝謝。現在,我正在通過不交換視圖,但這不是一個解決方案... – Moshe 2011-02-15 05:05:51

回答

2

如果我解決這個問題,我會做以下

  1. 一個添加到父視圖交替意見,不改變視圖屬性
  2. 爲不需要全視圖交換的視圖創建設計,但重新排列或隱藏視圖的子元素。
  3. 從層次結構

我會非常努力不完全換出視圖方向的緣故根視圖控制器存在的任何模式。即使解決了這個問題,似乎仍然會出現問題。

0

如果您交換視圖,您還應該交換我認爲的模態視圖。

例如,如果您展示popover控制器 - 它會自動解散並隨UI旋轉出現。

0

這是一個想法:保持主視圖不變,但將子視圖更改爲縱向或橫向視圖。像這樣:

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

    // Remove the current subview from the main view 
    if (self.view.subviews.count) { 
     [self.view.subviews objectAtIndex:0] removeFromSuperview]; 
    } 

    // Use your if-else block, but change [self setView:] for [self.view addSubview:] 
} 

所以現在當你創建你的模態,它會被鏈接到你的控制器,它現在有一個恆定的主視圖。

請注意,我沒有測試這個,因爲我在兩週後關閉了編碼...... 祝你好運!