在iPad上旋转时如何阻止模态视图消失?

Mos*_*she 6 objective-c rotation uikit ipad ios

willRotateToInterfaceOrientation当我的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];
}   
}
Run Code Online (Sandbox Code Playgroud)

小智 2

如果我要解决这个问题,我会执行以下操作之一

  1. 将备用视图添加到父视图,而不更改视图属性
  2. 为视图创建不需要完整视图交换但重新排列或隐藏视图子元素的设计。
  3. 显示层次结构的根 ViewController 中的任何模式

我会非常努力地避免为了方向而完全改变视图。即使您解决了这个问题,似乎仍会继续出现问题。