我想在某个角落添加一个浮动关闭 (x) 按钮UIModalPresentationPageSheet
看法。效果如下:
但是将其添加到父视图会使其显示在页面表后面(并且也无法点击),并将其添加到页面表将使其部分隐藏,因为它超出了视图区域。
还有更好的解决办法吗?
任何建议表示赞赏。
您可以尝试将其添加到最上面的应用程序窗口:
add.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentViewController:add animated:YES completion:^{
[[[[UIApplication sharedApplication] windows] lastObject] addSubview:button];
}];
这应该为您提供正确的视图,以允许按钮出现在模式顶部并接收触摸事件。
--edit--
要定位按钮,您可以尝试如下操作:
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 的框架。然后,您可以将按钮的原点设置为偏移并设置调整后的框架。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)