首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIPopoverPresentationController淡入

UIPopoverPresentationController淡入
EN

Stack Overflow用户
提问于 2015-11-14 11:48:08
回答 2查看 2.2K关注 0票数 4

在我的iOS8+项目中,我使用UIPopoverPresentationController表示一个UIViewController:

代码语言:javascript
复制
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)

代码语言:javascript
复制
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
    return UIModalPresentationNone;
}

目前,它在呈现的UIViewController上立即出现(并且随着淡出而消失)。有人能告诉我如何定制这个演示文稿,这样我就可以让它褪色吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-01-12 08:41:45

我能够做到这一点,只需设置:

代码语言:javascript
复制
[self.view setAlpha: 0.0];
[self.popoverPresentationController.containerView setAlpha:0.0];

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

代码语言:javascript
复制
[UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{

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

} completion:nil];

viewDidAppear:方法中。

票数 10
EN

Stack Overflow用户

发布于 2016-01-12 08:29:24

这是我的建议:

代码语言:javascript
复制
 - (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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33708065

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档