如何在iOS7的UIPopoverController中禁用较暗的透明效果?

我使用UIPopoverController在iPad iOS7中popup视图,如下所示:

if (!self.popover) { UIViewController *popupVC = [[UIViewController alloc] init]; [popupVC.view addSubview:thePopupView]; popupVC.preferredContentSize = CGSizeMake(240, 140); self.popover = [[UIPopoverController alloc] initWithContentViewController:popupVC]; self.popover.delegate = self; } [self.popover presentPopoverFromBarButtonItem:barButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

但是当popover激活时, 屏幕会变暗,而这个效果不会影响iOS6中的其他视图。

如何克服这个问题? 谢谢!

如果您的意思是在popoverBackgroundViewClass下插入的调光视图,则只有一种解决方法 – 使用自定义popoverBackgroundViewClass

这很复杂,但不像你想的那么复杂。

另一种方法是遍历popover视图堆栈并手动删除调UIPopoverController视图,如UIPopoverController子类中所示:

 @property (nonatomic, assign) BOOL showsDimmingView; .... - (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated { [super presentPopoverFromBarButtonItem:item permittedArrowDirections:arrowDirections animated:animated]; if (!_showsDimmingView) { [self removeDimmingView:[[UIApplication sharedApplication].keyWindow.subviews lastObject]]; } } - (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated { [super presentPopoverFromRect:rect inView:view permittedArrowDirections:arrowDirections animated:animated]; if (!_showsDimmingView) { [self removeDimmingView:[[UIApplication sharedApplication].keyWindow.subviews lastObject]]; } } - (void)removeDimmingView:(UIView *)subview { for (UIView *sv in subview.subviews) { if (sv.alpha == 0.15f && [sv isKindOfClass:NSClassFromString(@"_UIPopoverViewBackgroundComponentView")]) { sv.alpha = 0.f; } const CGFloat *components = CGColorGetComponents(sv.backgroundColor.CGColor); if (sv.backgroundColor && (components[1] == 0.15f || sv.alpha == 0.15f)) { [sv removeFromSuperview]; } [self removeDimmingView:sv]; } }