Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPopoverPresentationController Fade In

In my iOS8+ project, I am presenting a UIViewController using UIPopoverPresentationController:

vc.modalPresentationStyle = UIModalPresentationPopover;
vc.popoverPresentationController.delegate = self;
vc.popoverPresentationController.sourceView = self.someView.superview;
vc.popoverPresentationController.sourceRect = self.someView.frame;
vc.popoverPresentationController.backgroundColor = [UIColor clearColor];
vc.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown;
vc.preferredContentSize = CGSizeMake(200, 500);

(Also implementing the delegate method to force as popover)

-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
    return UIModalPresentationNone;
}

Currently, it appears instantly over the presenting UIViewController (and disappears with fade out). Can anyone direct me towards customizing this presentation so I can make it fade in?

like image 472
ZeMoon Avatar asked Dec 24 '22 12:12

ZeMoon


1 Answers

I was able to achieve the effect, by simply setting:

[self.view setAlpha: 0.0];
[self.popoverPresentationController.containerView setAlpha:0.0];

in the popover viewController's viewWillAppear: method, and then calling

[UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{

    [self.view setAlpha:1.0];
    [self.popoverPresentationController.containerView setAlpha:1.0];

} completion:nil];

in the viewDidAppear: method.

like image 112
ZeMoon Avatar answered Jan 12 '23 09:01

ZeMoon