gpt4 book ai didi

ios - 如何将关闭按钮添加到 UIModalPresentationFormSheet 中显示的模态视图角?

转载 作者:可可西里 更新时间:2023-11-01 05:56:04 27 4
gpt4 key购买 nike

我想在 UIModalPresentationPageSheet View 的一角添加一个 float 关闭 (x) 按钮。效果如下:

enter image description here

但是将它添加到父 View 会使它出现在页面表后面(并且也无法点击)并且将它添加到页面表会使它的一部分隐藏,因为它在 View 区域之外。

有没有更好的解决方案?

如有任何建议,我们将不胜感激。

最佳答案

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

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

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

--编辑--

要定位按钮,您可以尝试这样的操作:

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 的框架。然后,您可以将按钮的原点设置为偏移并设置调整后的框架。

关于ios - 如何将关闭按钮添加到 UIModalPresentationFormSheet 中显示的模态视图角?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15983731/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com