7

我使用 UIPopoverController 在 iPad iOS7 中弹出一个视图,如下所示:

    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 中的其他视图。

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

4

2 回答 2

4

如果您指的是在弹出框下方插入的调光视图,则只有一种解决方法 - 使用自定义popoverBackgroundViewClass.

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

于 2013-09-19T15:15:28.730 回答
2

另一种方法是遍历弹出视图堆栈并手动删除调光视图,如下面的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];
    }
}
于 2013-11-14T19:10:53.707 回答