【问题标题】:Objective-C Modal View Controller with Transparent Background具有透明背景的 Objective-C 模态视图控制器
【发布时间】:2016-08-16 10:07:42
【问题描述】:

我想创建一个具有透明背景的模态视图控制器,但是当我尝试将背景的 alpha 设置为 0.5 时,它只会让其后面的视图完全变黑。这是因为背景视图在转换后被移除。

self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
[self setModalPresentationStyle:UIModalPresentationFullScreen];
[self setDefinesPresentationContext:YES];

然后呈现视图控制器代码

SecondViewController *alertView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self presentViewController:alertView animated:YES completion:nil];

请看链接 image/linke.gif

【问题讨论】:

标签: objective-c xcode uiviewcontroller


【解决方案1】:

firstViewController 中的按钮操作中尝试此代码以更改视图控制器并呈现一个新类secondViewController

  secondViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"secondViewController"];

    VC.view.backgroundColor=[UIColor colorWithWhite:0 alpha:0.1f];
    VC.modalPresentationStyle=UIModalPresentationOverCurrentContext;
    [self presentViewController:VC animated:NO completion:nil];

【讨论】:

    猜你喜欢
    • 2015-02-20
    • 2016-01-11
    • 1970-01-01
    • 2015-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多