我有两个视图控制器,称它们为“ViewControllerA”和“ViewControllerB”。加载应用程序时,将显示ViewControllerA。在ViewControllerA的touchesEnded:withEvent:
中,它在ViewControllerB上调用presentViewController:
。 ViewControllerB的加载工作正常;唯一的问题是,当它们转换时,ViewControllerA变黑。即使在转换到ViewControllerB时,如何使ViewControllerA继续查看其内容?如果它是相关的,我使用自定义转换,在此处演示:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.7f];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationRepeatCount:1.0f];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
toViewController.view.frame = self.view.bounds;
[self presentViewController:toViewController animated:NO completion:nil];
[UIView commitAnimations];
答案 0 :(得分:1)
首先,您应该使用自iOS 4以来推荐的基于块的新方法。如果使用具有完成块的方法,则可以执行presentViewController:在那里进行动画处理(当您呈现带有动画的视图控制器时,它会立即删除旧控制器的视图,这就是你的问题)。这是一个将视图从小尺寸扩展到完整尺寸的示例:
-(IBAction)doStuff:(id)sender {
self.toViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ToVC"];
self.toViewController.view.transform = CGAffineTransformMakeScale(.01, .01);
[self.view.window addSubview:self.toViewController.view];
[UIView animateWithDuration:2.0 animations:^{
self.toViewController.view.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
[self presentViewController:self.toViewController animated:NO completion:nil];
}];
}