Present UIPopoverController in same position with changing just arrow offset(将 UIPopoverController 呈现在相同位置,仅更改箭头偏移量)
问题描述
我的目标是保持 UIPopoverController 的坐标相同,只需更改箭头偏移量.所以基本上我有三个按钮触摸它们中的每一个都会显示一个弹出窗口.呈现此弹出框时,它会更改屏幕上的位置,但我不希望那样.为了更清楚地查看屏幕截图:
My goal is to keep same coordinates for a UIPopoverController with just changing arrow offset. So basically i have three buttons touching each of them shows up a popover. When presenting this popover it changes position on the screen, but i do not want that. To be more clear look at screenoshots:
推荐答案
对于我的弹出框,我希望箭头位于左上角而不是顶部居中(这是默认设置).
For my popover I wanted the arrow to be top-left instead of top-center (which is default).
通过设置 UIPopoverController 的 popoverLayoutMargins
属性,我设法得到了下面的结果(屏幕截图).您可以使用它来减少 UIPopoverController 内部计算中使用的屏幕区域,以确定在何处显示弹出框.
I've managed to get the result below (screenshot) by setting the popoverLayoutMargins
property of the UIPopoverController. You can use it to reduce the screen-area used in the internal calculations of the UIPopoverController to determine where to show the popover.
代码:
// Get the location and size of the control (button that says "Drinks")
CGRect rect = control.frame;
// Set the width to 1, this will put the anchorpoint on the left side
// of the control
rect.size.width = 1;
// Reduce the available screen for the popover by creating a left margin
// The popover controller will assume that left side of the screen starts
// at rect.origin.x
popoverC.popoverLayoutMargins = UIEdgeInsetsMake(0, rect.origin.x, 0, 0);
// Simply present the popover (force arrow direction up)
[popoverC presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
我认为您可以通过调整上述内容来获得所需的结果.
I think you'll be able to get the desired result by tweaking the above.
这篇关于将 UIPopoverController 呈现在相同位置,仅更改箭头偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 UIPopoverController 呈现在相同位置,仅更改箭头
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01