我是通过子类UIPopoverBackgroundView (使用此tutorial)并使用UIPopoverController来实现自定义弹出。不幸的是,一旦我指定了自定义popoverBackgroundViewClass,本机调暗的背景就消失了。在使用自定义UIPopoverBackgroundView时,有什么方法可以使背景变暗吗?还有其他可以用来模拟本机行为的解决方案吗?
发布于 2014-02-12 21:11:09
不知道为什么这会被否决,这是一个很好的问题,因为当您实现一个自定义UIPopoverBackgroundView时,没有设置调暗的背景。在研究这个问题时,我决定最好的方法是自己设定它!
在创建popover视图之前,我创建了一个“掩码视图”,该视图将被添加到该视图之前。这段代码还包括一个很好的淡出效果:
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];要删除视图,请将其插入处理弹出视图消失的方法中:
[UIView transitionWithView:self.view
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^ {
[self.customPopoverMaskView removeFromSuperview];
}
completion:nil];对我来说很管用。编码愉快!
Aaron
发布于 2014-12-12 22:38:28
您所需要的只是在initWithFrame中添加下一个代码:实现UIPopoverBackgroundView的方法。
UIView *dimView = [[UIView alloc] initWithFrame:CGRectMake(0 - self.frame.origin.x,
0 - self.frame.origin.y,
[UIScreen mainScreen].bounds.size.width,
[UIScreen mainScreen].bounds.size.height)];
dimView.backgroundColor = [UIColor blackColor];
dimView.alpha = 0.15;
dimView.userInteractionEnabled = NO;
[self addSubview:dimView];它的工作原理与默认的Apple实现相同。
https://stackoverflow.com/questions/21167466
复制相似问题