如何将变暗的背景添加到自定义 UIPopoverBackgroundView [英] How to add dimmed background to a custom UIPopoverBackgroundView

查看:89
本文介绍了如何将变暗的背景添加到自定义 UIPopoverBackgroundView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过继承 UIPopoverBackgroundView(使用此教程)并通过使用 UIPopoverController.不幸的是,一旦我指定自定义 popoverBackgroundViewClass,本机变暗的背景就会消失.使用自定义 UIPopoverBackgroundView 时,有没有办法让背景变暗?我可以用来模拟本机行为的任何其他解决方案?

I am making custom popover by subclassing UIPopoverBackgroundView (using this tutorial) and presenting it by using UIPopoverController. Unfortunately as soon as I specify custom popoverBackgroundViewClass the native dimmed background disappears. Is there any way to leave the dimmed background when using custom UIPopoverBackgroundView? Any other solution that I can use to simulate native behaviour?

推荐答案

不知道为什么会被否决,这是一个很好的问题,因为当您实现自定义 UIPopoverBackgroundView 时,不会设置变暗的背景.在研究这个问题时,我确定最好的方法是自己设置!

Not sure why this got down voted, it's a good question because when you implement a custom UIPopoverBackgroundView, the dimmed background doesn't get set. In researching this problem, I determined the best approach is to set it myself!

就在创建弹出框视图之前,我创建了一个遮罩视图",它将在弹出框之前添加到视图中.此代码还包括一个不错的淡入效果:

Just before creating the popover view, I create a "mask view" that will be added to the view before the popover. This code includes a nice fade in effect as well:

self.customPopoverMaskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    self.customPopoverMaskView.backgroundColor = [UIColor blackColor];
    self.customPopoverMaskView.alpha = 0.3f;

    [UIView transitionWithView:self.view
                      duration:0.3
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^ {
                        [self.view addSubview:self.customPopoverMaskView];
                    }
                    completion:nil];

并删除视图,将其插入处理弹出视图消失的方法中:

And to remove the view, plug this into the method(s) that handle the popover view disappearing:

[UIView transitionWithView:self.view
                  duration:0.3
                   options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^ {
                    [self.customPopoverMaskView removeFromSuperview];
                }
                completion:nil];

对我来说效果很好.快乐编码!

Works well for me. Happy coding!

亚伦

这篇关于如何将变暗的背景添加到自定义 UIPopoverBackgroundView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆