3

我正在尝试在以下代码中调试一个非常奇怪的问题:

if(condition1) {
   ImageViewController* imageViewer = [[ImageViewController alloc] initWithImageData:tappedItem];
   [self presentViewController:imageViewer animated:YES completion:^{
      [imageViewer loadImage];
   }];
}
else if(condition2) {
   DocumentViewController* docViewer = [[DocumentViewController alloc] init];
   [self presentViewController:docViewer animated:YES completion:nil];
}

换句话说,根据 和 的状态,condition1两个condition2子类之一UIViewController将以模态方式显示给用户。

在第二种情况下,一切都很好,但在第一种情况下,视图控制器没有显示通常的动画,显示它从屏幕底部滑入。相反,在短暂的延迟之后,它突然出现,覆盖了整个屏幕。另一个奇怪的是,在解雇动画中,视图控制器内的图像视图是透明的。

删除完成块没有效果。用 的实例替换我的视图控制器UIViewController也没有任何效果,除了证明出于某种原因,动画也不适用于UIViewController实例。

考虑到我可能在等方面做错了什么viewDidLoad,我尝试注释掉视图加载/显示方法,但无济于事。

将视图控制器推送到导航堆栈不是一种选择,因为该应用程序有一个标签栏,我不想被看到。

更新

ImageViewController用 a替换我的实例DocumentViewController确实会产生动画。现在的问题变成了:我可以做些什么ImageViewController来搞乱动画?

4

4 回答 4

4

我找到了解决方案,但我仍然不知道真正的原因是什么。

UIViewController解决方法是在其方法中为正在模态显示的视图设置背景颜色,viewDidload例如

self.view.backgroundColor = [UIColor grayColor];

如果我弄清楚到底发生了什么,我会在这里发帖。

于 2013-05-28T12:02:20.510 回答
0

如何在标签栏控制器上显示视图控制器:

if(condition1) {
   ImageViewController* imageViewer = [[ImageViewController alloc] initWithImageData:tappedItem];
   [self.tabBarController presentViewController:imageViewer animated:YES completion:^{
      [imageViewer loadImage];
   }];
}
else if(condition2) {
   DocumentViewController* docViewer = [[DocumentViewController alloc] init];
   [self.tabBarController presentViewController:docViewer animated:YES completion:nil];
}
于 2013-05-24T15:41:22.330 回答
0

它也发生在我身上......改变背景颜色并没有真正帮助。我做了以下事情 - 结果非常好:

 -(void) viewWillAppear:(BOOL)animated
 {
     [super viewWillAppear:NO];
     self.view.userInteractionEnabled = FALSE;
     self.view.hidden = TRUE;
     self.navigationController.navigationBar.alpha = 0;
}

 -(void) viewDidAppear:(BOOL)animated
 {
     [super viewDidAppear:NO];
     float width = self.view.frame.size.width;
     float height = self.view.frame.size.height;
     self.view.frame = CGRectMake(0, height, width, height);
     self.view.hidden = FALSE;
     [UIView animateWithDuration:0.7f animations:^{
     self.view.frame = CGRectMake(0, 0, width, height);
    self.navigationController.navigationBar.alpha = 1;
} completion:^(BOOL finished){
    self.view.userInteractionEnabled = TRUE;

}];
 }
于 2014-06-25T16:38:02.930 回答
0

在 iOS 8 中设置背景颜色对我有用。还可以取消选中 Interface Builder 中的不透明设置!

于 2014-11-20T12:24:55.633 回答