UIPopoverPresentationController Fade In
Asked Answered
K

2

5

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?

Keynesianism answered 14/11, 2015 at 11:48 Comment(2)
you can try github.com/AugustRush/ARTransitionAnimator for UIViewController transition animationUndis
@Madangupta thanks. Will do.Keynesianism
K
11

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.

Keynesianism answered 12/1, 2016 at 8:41 Comment(3)
I tried your method, i do not think it great, do you think?Gallnut
I've done the fade in animation in prepareForPopoverPresentation: and replaced the fade out animation in popoverPresentationControllerShouldDismissPopover (and then dismissed with no animation in my animation's completion). This also looks better with the popup's arrow fade out.Hammonds
@Hammonds that definitely makes the solution better looking.Keynesianism
G
0

This is my suggest:


 - (void)showRight:(NSString*)title{
    UIButton *rightBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.exclusiveTouch = YES;
    rightBtn.frame=CGRectMake(0, 0, 70, 44);
    rightBtn.titleLabel.font=[UIFont systemFontOfSize:15];
    [rightBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [rightBtn setTitle:title forState:UIControlStateNormal];
    rightBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
    [rightBtn addTarget:self action:@selector(onClickRight:) forControlEvents:UIControlEventTouchUpInside];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];


}


-(void)onClickRight:(UIButton *)bar{

    NSLog(@"bubble");
    POPViewController *popVC = [[POPViewController alloc] init];

    UINavigationController *destNav = [[UINavigationController alloc] initWithRootViewController:popVC];/*-> Here popVC is a controller you want to show in popoverview *******/
    popVC.preferredContentSize = CGSizeMake(280,200);
    destNav.modalPresentationStyle = UIModalPresentationPopover;
    _dateTimePopover8 = destNav.popoverPresentationController;
    _dateTimePopover8.delegate = self;
    _dateTimePopover8.sourceView = self.view;
//    _dateTimePopover8.sourceRect = CGRectMake(0, 64, 70, 44);// CGRectMake(SCREEN_W-20, 64, 70, 44);;//->Here  Rect  is you want show position


    // ->here I got  the rightBarButtonItem position and  show
    CGRect frame = [[self.navigationItem.rightBarButtonItem valueForKey:@"view"] frame];
    frame.origin.y = frame.origin.y+10;
    frame.origin.x = frame.origin.x+15;
    _dateTimePopover8.sourceRect = frame;


    destNav.navigationBarHidden = YES;
    [self presentViewController:destNav animated:YES completion:nil];
}

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

-(void)hideIOS8PopOver
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

I hope I could help you!

Gallnut answered 12/1, 2016 at 8:29 Comment(4)
Does this make the popover fade in instead of appearing instantly?Keynesianism
change: popVC.preferredContentSize = CGSizeMake(280,200); ---> popVC.preferredContentSize = CGSizeMake(20,30); and change : [self presentViewController:destNav animated:YES completion:nil]; ----> [self presentViewController:destNav animated:YES completion:^{ [UIView animateWithDuration:1 animations:^{ popVC.preferredContentSize = CGSizeMake(200,300); }]; }]; *************************** did you want see this style ?Gallnut
fixing one bug for answer : ************************************************ popVC.preferredContentSize = CGSizeMake(200,1); ******************************************************************************* [self presentViewController:destNav animated:NO completion:^{ [UIView animateWithDuration:0.7 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ popVC.preferredContentSize = CGSizeMake(200,300); } completion:nil]; }];Gallnut
Please edit your existing answer instead of posting a comment.Keynesianism

© 2022 - 2024 — McMap. All rights reserved.