我有两个 View Controller ,将它们称为“ViewControllerA”和“ViewControllerB”。当应用程序加载时,将显示 ViewControllerA。在 ViewControllerA 的 touchesEnded:withEvent:
中,它调用 ViewControllerB 上的 presentViewController:
。 ViewControllerB 的加载工作正常;唯一的问题是,当它们转换时,ViewControllerA 会变黑。如何让 ViewControllerA 在转换到 ViewControllerB 时继续查看其内容?如果相关,我使用自定义转换,如下所示:
[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];
最佳答案
首先,您应该使用自 iOS 4 以来推荐的基于 block 的较新方法。如果您使用具有完成 block 的方法,则可以在那里执行presentViewController:animated(当您呈现带有动画的 View Controller 时) ,它会立即删除旧 Controller 的 View ,所以这是你的问题)。下面是一个将 View 从小尺寸扩展到完整尺寸的示例:
-(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];
}];
}
关于ios - 在呈现另一个 View Controller 时,如何阻止 "from" View 变黑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18862141/