美文网首页
ios popover

ios popover

作者: 啷里个啷里个啷个里个啷 | 来源:发表于2018-07-26 13:37 被阅读0次

popover (iphone && ipad)

_setVC 为设置界面;

添加 <UIPopoverPresentationControllerDelegate>;

- (void)leftBtnClick:(UIButton*)sender{

    if(_setVC) {

        [self dismissViewControllerAnimated:YES completion:nil];

        _setVC=nil;

    }

    _setVC = [[ASettingViewController alloc] init];

    [_setVC setDelegate:self];

    //设置弹出的样式为popover

    _setVC.modalPresentationStyle = UIModalPresentationPopover;

    //设置弹出控制器的尺寸

    _setVC.preferredContentSize = CGSizeMake(120, 120);

    //设置popoverPresentationController的sourceRect和sourceView属性

    _setVC.popoverPresentationController.sourceRect = sender.bounds;

    _setVC.popoverPresentationController.sourceView = sender;

    //设置箭头方向

    _setVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;

    //设置背景色,包括箭头

    _setVC.popoverPresentationController.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.5];

    _setVC.popoverPresentationController.delegate = self;

    //弹出

    [self presentViewController:_setVC animated:YES completion:nil];

}

#pragma mark - UIPopoverPresentationControllerDelegate

//实现该代理方法,返回UIModalPresentationNone值,可以在iPhone设备实现popover效果

-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController*)controller{

    return UIModalPresentationNone;//不适配(不区分ipad或iPhone)

}

相关文章

网友评论

      本文标题:ios popover

      本文链接:https://www.haomeiwen.com/subject/dchbmftx.html