【问题标题】:present a controller with alpha is 0.5呈现一个 alpha 为 0.5 的控制器
【发布时间】:2014-09-04 09:41:05
【问题描述】:

vc命名的新UIViewController为例,然后调用

[self presentViewController:vc animated:YES completion:nil];

我希望 vc 看起来像透明或 alpha = 0.5,

我知道下面的代码可以做到这一点,但是现在的动画消失了,我想要透明动画,有什么想法吗?

self.modalPresentationStyle = UIModalPresentationCurrentContext;

【问题讨论】:

  • 如果新视图不是不透明的,请小心为它们设置动画 - 有时 iOS 使用不透明来隐藏其内置动画的工作原理,引入半透明可能看起来很糟糕。

标签: ios objective-c animation uinavigationcontroller


【解决方案1】:

我不确定这是最好的解决方案,但您绝对可以非常简单地自己制作动画:

NewViewController *newVC = [[NewViewController alloc] init];
newVC.view.frame = CGRectMake(0, SCREEN_HEIGHT, self.view.frame.size.width, self.view.frame.size.height);
newVC.view.alpha = 0.5;    

[self addChildViewController:newVC];
[self.view addSubview:newVC.view];

[UIView animateWithDuration:0.3 animations:^{
    newVC.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
} completion:nil];

【讨论】:

    【解决方案2】:

    如果给视图设置不透明度,则所有按钮、标签等也将具有不透明度。

    请按照以下步骤操作...

    为查看提供透明颜色。

    self.view.backgroundColor = [UIColor clearColor];
    

    然后添加 uiimageview 并将背景色设为透明色,然后将不透明度设为 0.5。

    myImage.backgroundColor = [UIColor clearColor];
    myImage.alpha = 0.5;
    

    【讨论】:

    • 我希望呈现的 ViewController 看起来是透明的,而不是当前的 ViewController。
    • @Geaka :好的,那就用yourView.backgroundColor
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    • 2020-07-14
    相关资源
    最近更新 更多