如何在iPhone中使用presentViewController时保持背景透明?

时间:2013-08-02 05:00:29

标签: ios uiviewcontroller

我希望像iOS iOS6中的UIActivityController一样保持背景透明 enter image description here

我尝试清除颜色和不透明但背景总是像这样黑(iPhone iOS5模拟器)

enter image description here

这是presentViewController代码:

    ShareViewController *controller = [[ShareViewController alloc] initWithNibName:@"ShareViewController_iPhone" bundle:nil];
    controller.delegate = self;

    [self presentViewController:controller animated:YES completion:^{
        NSLog(@"Activity complete");
    }];

请帮忙!谢谢!

2 个答案:

答案 0 :(得分:1)

查看您要做的是在您提到的自定义UIView后面添加UIActionsheet。在这里你可以做的是将UIView的背景颜色保持为白色,然后保持其alpha = 0.5。

当您解雇UIActionsheet时,removeFromSuperview UIView也可以添加{{1}}。

答案 1 :(得分:0)

使用[UIView transitionWithView]来定义您的自定义动画,而不是presentViewController。

  • 首先将视图控制器保留在某处。 (如果您使用ARC,则将其作为父视图控制器上的属性)。

  • 将视图控制器的视图作为子视图添加到当前VC的视图中。将帧设置为CGRectMake(0,screenBottom,screenWidth,screenHeight / 2);

  • 通过更改框架以使其滑动到屏幕上进行动画处理。

    [UIView transitionWithView:<#(UIView *)view#> duration:0.5 options:nil
      animations:^
      {
          view.frame = CGRectMake(0, screenHeight / 2, screenWidth, screenHeight/ 2);
      } completion:nil];