2015-11-14 10 views
1

В моем проекте iOS8 +, я представления UIViewController с помощью UIPopoverPresentationController:UIPopoverPresentationController Fade In

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

(также реализует метод делегата, чтобы заставить, как пирог)

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

В настоящее время он появляется сразу над представляющий UIViewController (и исчезает с постепенным исчезновением). Может ли кто-нибудь направлять меня к настройке этой презентации, чтобы я мог ее угаснуть?

+0

вы можете попробовать https://github.com/AugustRush/ARTransitionAnimator для анимации перехода UIViewController –

+0

@Madangupta спасибо. Сделаю. – ZeMoon

ответ

4

мне удалось добиться эффекта, просто установив:

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

в viewWillAppear: методе поповер ViewController, а затем вызвать

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

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

} completion:nil]; 

в методе viewDidAppear:.

+0

Я пробовал ваш метод, я не думаю, что это здорово, как вы думаете? –

+1

По крайней мере, он работает по мере необходимости. – ZeMoon

+1

Я сделал fade в анимации в 'prepareForPopoverPresentation:' и заменил анимацию fade out в 'popoverPresentationControllerShouldDismissPopover' (а затем уволен без анимации в завершении моей анимации). Это также выглядит лучше, когда стрелка всплывающего окна исчезает. – Geva

0

Это мой предлагаю:


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

Я надеюсь, что я мог бы вам помочь!

+0

Это делает popover исчезать вместо того, чтобы появляться мгновенно? – ZeMoon

+0

изменение: popVC.preferredContentSize = CGSizeMake (280,200); ---> popVC.preferredContentSize = CGSizeMake (20,30); и изменение: [self presentViewController: destNav animated: YES завершение: nil]; ----> [собственной presentViewController: destNav анимированные: ДА завершение:^{ [UIView animateWithDuration: 1 анимации:^{ popVC.preferredContentSize = CGSizeMake (200300); }]; }]; *************************** Вы хотите увидеть этот стиль? –

+0

исправление один ошибка для ответа: ******************************************* ***** popVC.preferredContentSize = CGSizeMake (200,1); ************************************************* ****************************** [self presentViewController: destNav animated: NO завершение:^{ [UIView animateWithDuration: 0.7 delay : 0.0 опции: UIViewAnimationOptionCurveLinear анимации:^{ popVC.preferredContentSize = CGSizeMake (200 300); } завершение: ноль]; }]; –