使用透明度和动画呈现一个视图控制器

7
我在应用程序代理中设置self.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;,以便我可以呈现一个视图控制器并使视图透明(请参见此SO 问题)。
这很好用,唯一的问题是当视图控制器被呈现时无法进行动画。有人解决了这个问题吗?如果没有,我还有哪些其他选择?
我要呈现的视图控制器是一个“演示”,由一个UIScrollView和一个UIPageControl组成,应该“悬停”在界面上,因此您可以稍微看到其边缘的背景。
2个回答

9
我最终做了这个:

我最终的做法是:

AppDelegate *appDelegate = [AppDelegate sharedAppDelegate];

// Set the root VC modal presentation style
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;

WalkthroughViewController *walkthroughVC = [[WalkthroughViewController alloc] initWithNibName:nil bundle:nil];

[self presentViewController:walkthroughVC animated:NO completion:nil];

// Manually animate the view
walkthroughVC.view.alpha = 0;
[UIView animateWithDuration:0.5 animations:^{
       walkthroughVC.view.alpha = 1;
}];

// Reset root VC modal presentation style 
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;

当我从AppDelegate中调用回调函数(例如Twitter身份验证回调)并呈现透明视图控制器时,这对我也很有用。 - morph85

0
你可以使用基本视图控制器中存在的包含视图。不要呈现模态,而是通过动画将包含视图的位置上移以模拟模态呈现。
例如...
TransparentViewController *viewController = [[TransparentViewController alloc] init];
viewController.view.frame = CGRectMake(0, 480, 320, 480);
self.containmnetView = viewController.view;

要呈现这个,做如下操作:

[UIView animateWithDuration:0.5f animations:^{
    self.containmentView.frame = CGRectMake(0, 0, 320, 480);
}];

我希望这可以帮助到你。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接