2011-02-14 107 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:] 
} 

所以现在当你创建你的模态,它会被链接到你的控制器,它现在有一个恒定的主视图。

请注意,我没有测试这个,因为我在两周后关闭了编码...... 祝你好运!