如何将关闭按钮添加到 UIModalPresentationPageSheet 中显示的模态视图角? [英] how to add close button to modal view corner which is presented in UIModalPresentationPageSheet?

查看:22
本文介绍了如何将关闭按钮添加到 UIModalPresentationPageSheet 中显示的模态视图角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 UIModalPresentationPageSheet 视图的角落添加一个浮动关闭 (x) 按钮.效果如下:

I want to add a floating close (x) button at the corner of an UIModalPresentationPageSheet View. The effect is like below:

但是将其添加到父视图会使其显示在页面表后面(并且也无法点击),并且将其添加到页面表会使其部分隐藏,因为它不在视图区域之外.

But adding it to the parent view makes it appear behind the Page Sheet (and also impossible to tap) and adding it to the Page Sheet will make part of it hidden, since it's out of the view area.

有没有更好的解决方案?

Is there any better solution?

欢迎提出任何建议.

推荐答案

您可以尝试将其添加到最顶层的应用程序窗口:

You can try and add it to the the topmost application window:

    add.modalPresentationStyle = UIModalPresentationPageSheet;
    [self presentViewController:add animated:YES completion:^{
        [[[[UIApplication sharedApplication] windows] lastObject] addSubview:button];
    }];

这应该为您提供正确的视图,以允许按钮出现在模式顶部并接收触摸事件.

This should give you the right view to allow the button to appear on top of the modal and receive touch events.

--编辑--

要定位按钮,您可以尝试以下操作:

To position the button you can try something like this:

self.modalPresentationStyle = UIModalPresentationFormSheet;
add.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:pvc animated:YES completion:^{
    CGRect parentView = pvc.view.superview.frame;
    CGRect buttonFrame = button.frame;
    buttonFrame.origin = CGPointMake(parentView.origin.x - buttonFrame.size.width/2.0f, parentView.origin.y - buttonFrame.size.height/2.0f);

    [button setFrame:buttonFrame];
    [[[[UIApplication sharedApplication] windows] lastObject] addSubview:button];
}];

这将获得已呈现的modalView的框架.然后,您可以将按钮的原点设置为偏移并设置调整后的框架.

This will get the frame of the modalView that has been presented. You can then set your button's origin to be offset and set the adjusted frame.

这篇关于如何将关闭按钮添加到 UIModalPresentationPageSheet 中显示的模态视图角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆