【问题标题】:Presenting a view controller with transparency and animation呈现具有透明度和动画的视图控制器
【发布时间】:2013-03-25 08:36:13
【问题描述】:

我在我的 Application Delegate 中设置了 self.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;,这样我就可以呈现一个视图控制器并让视图变得透明(参见这个 SO question)。

这很好用,唯一需要注意的是,当呈现视图控制器时,我无法制作动画。有没有人让这个工作?如果没有,我还有什么其他选择?

我展示的视图控制器是一个“演练”,由UIScrollViewUIPageControl 组成,它应该“悬停”在界面上,以便您可以在边缘稍微看到它的背景。

【问题讨论】:

    标签: ios cocoa-touch animation uiviewcontroller transparency


    【解决方案1】:

    您可以使用基本视图控制器中存在的包含视图。不是呈现模态,而是将包含视图的位置设置为动画以模拟模态呈现。

    例如...

    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);
    }];
    

    我希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      我最终这样做了:

      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 身份验证回调)并呈现透明视图控制器时,这对我也很有用。
      猜你喜欢
      • 2015-02-20
      • 1970-01-01
      • 2015-04-06
      • 1970-01-01
      • 2015-02-24
      • 2016-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多