Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable darker transparent effect in UIPopoverController in iOS7?

I use UIPopoverController to popup an view in iPad iOS7 like this:

    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];

But when popover active, it make screen darker while this effect not affect other views in iOS6.

How to overcome this issue? Thanks!

like image 616
LE SANG Avatar asked Sep 19 '13 14:09

LE SANG


2 Answers

If you mean the dimming view that is inserted under the popover, there is only one workaround - use a custom popoverBackgroundViewClass.

It's complicated, but not as complicated as you might think.

like image 87
Sulthan Avatar answered Dec 15 '22 01:12

Sulthan


Another method is to traverse the popover view stack and remove the dimming view manually, as shown here in a UIPopoverController subclass:

@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];
    }
}
like image 41
mndmatt Avatar answered Dec 15 '22 01:12

mndmatt