問題描述
我的目標(biāo)是保持 UIPopoverController 的坐標(biāo)相同,只需更改箭頭偏移量.所以基本上我有三個(gè)按鈕觸摸它們中的每一個(gè)都會(huì)顯示一個(gè)彈出窗口.呈現(xiàn)此彈出框時(shí),它會(huì)更改屏幕上的位置,但我不希望那樣.為了更清楚地查看屏幕截圖:
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:
推薦答案
對(duì)于我的彈出框,我希望箭頭位于左上角而不是頂部居中(這是默認(rèn)設(shè)置).
For my popover I wanted the arrow to be top-left instead of top-center (which is default).
通過設(shè)置 UIPopoverController 的 popoverLayoutMargins
屬性,我設(shè)法得到了下面的結(jié)果(屏幕截圖).您可以使用它來減少 UIPopoverController 內(nèi)部計(jì)算中使用的屏幕區(qū)域,以確定在何處顯示彈出框.
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];
我認(rèn)為您可以通過調(diào)整上述內(nèi)容來獲得所需的結(jié)果.
I think you'll be able to get the desired result by tweaking the above.
這篇關(guān)于將 UIPopoverController 呈現(xiàn)在相同位置,僅更改箭頭偏移量的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!