【问题标题】:UIPopoverPresentationController Fade InUIPopoverPresentationController 淡入
【发布时间】:2015-11-14 11:48:08
【问题描述】:

在我的 iOS8+ 项目中,我使用 UIPopoverPresentationController 呈现 UIViewController:

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

(也实现了委托方法强制作为popover)

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

目前,它会立即出现在呈现的 UIViewController 上(并随着淡出而消失)。谁能指导我自定义此演示文稿以便让它淡入淡出?

【问题讨论】:

标签: ios uipopovercontroller uipopover


【解决方案1】:

我可以通过简单的设置来达到效果:

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

在popover viewController的viewWillAppear:方法中,然后调用

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

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

} completion:nil];

viewDidAppear: 方法中。

【讨论】:

  • 我试过你的方法,我觉得不太好,你觉得呢?
  • 我已经在prepareForPopoverPresentation: 中完成了淡入动画,并在popoverPresentationControllerShouldDismissPopover 中替换了淡出动画(然后在我的动画完成中没有动画就被解雇了)。随着弹出窗口的箭头淡出,这看起来也更好。
  • @Geva 绝对让解决方案看起来更好看。
【解决方案2】:

这是我的建议:


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

希望能帮到你!

【讨论】:

  • 这是否会使弹出框淡入而不是立即出现?
  • 更改:popVC.preferredContentSize = CGSizeMake(280,200); ---> popVC.preferredContentSize = CGSizeMake(20,30);并更改:[se​​lf presentViewController:destNav animated:YES completion:nil]; ----> [self presentViewController:destNav 动画:YES 完成:^{ [UIView animateWithDuration:1 动画:^{ popVC.preferredContentSize = CGSizeMake(200,300); }]; }]; ****************************** 你想看这种风格吗?
  • 修复一个错误以获得答案:************************************ ************ popVC.preferredContentSize = CGSizeMake(200,1); ****************************************************** ***************************** [self presentViewController:destNav animated:NO completion:^{ [UIView animateWithDuration:0.7 delay:0.0 options :UIViewAnimationOptionCurveLinear 动画:^{ popVC.preferredContentSize = CGSizeMake(200,300); } 完成:无]; }];
  • 请编辑您现有的答案,而不是发表评论。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-28
相关资源
最近更新 更多