Mammadbayli
Mammadbayli

Reputation: 80

How can I get to dim everything except for the sourceView when presenting UIPopoverViewController?

I am developing a chat application similar to WhatsApp. When the user long presses a message a popover with options is presented. I want to dim everything in the background except for the popover and the sourceView of the popover. Like this: enter image description here

I tried this but all of the background gets dimmed:

- (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController {
    [[popoverPresentationController containerView] setBackgroundColor:[UIColor colorWithWhite:0 alpha:.72]];

}

Upvotes: 1

Views: 471

Answers (2)

Mammadbayli
Mammadbayli

Reputation: 80

I managed to do it by recreating a cell and adding it to the popover containerView:

- (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popoverPresentationController {
    [[popoverPresentationController containerView] setBackgroundColor:[UIColor colorWithWhite:0 alpha:.72]];

    MessageCellNode *messageNode = [[MessageCellNode alloc] init];

    UICollectionViewLayoutAttributes *attributes = [[self.collectionNode view] layoutAttributesForItemAtIndexPath:indexPathToSelect];
    CGRect cellRect = attributes.frame;

    CGRect rect = [[[self collectionNode] view] convertRect:cellRect toView:[[UIApplication sharedApplication] keyWindow]];

    [messageNode setFrame: rect];

    [[popoverPresentationController containerView]addSubview:[messageNode view]];
}

Result: enter image description here

Upvotes: 1

PinkalB
PinkalB

Reputation: 93

Javad

You can add blank in full screen in the presenting view. Set black background color and alpha 0.5 which will create dim effect.

Thank you

Upvotes: 1

Related Questions