问题描述
我想将 UIPopoverArrowDirection
移至左侧,以使实际箭头不再居中,而是从左侧移至25%,从右侧移至75%.
I want to move the UIPopoverArrowDirection
to the left such that the actual arrow is no longer centered but more 25% from the left and 75% from the right.
为了帮助我理解我的意思,请看两个屏幕截图,我希望它类似于第二个屏幕截图...
To help understand what I mean see the two screen shots I want it to be like the second one...
问题在于,没有真正的方法可以深入了解popover类...
The problem is that there is no real way to dig down into the popover class...
推荐答案
内置类已经可以通过指定"presentPopoverFromRect"并使其足够受约束来实现.
This is already doable with the builtin class by specifing "presentPopoverFromRect" and making that rect constrained enough.
下面的代码直接摘自上面的代码.多余的绒毛是因为小齿轮在UINavigationBar的UIToolbar中. r
是UIToolbar的框架,正在对其进行调整以使其击中正确的位置(箭头所示),或者会稍微偏离中心. MGSettingsView
是视图控制器(其中包含启用转换",启用夜间模式"等).
The below is code taken straight out of the code that results in the above. The extra fluff is because the little cogwheel thing is in a UIToolbar in a UINavigationBar. r
is the frame of the UIToolbar and it's being tweaked to hit the right spot (for the arrow) or it'd be slightly off-center. MGSettingsView
is the view controller (with "Enable transitions", "Enable night mode", etc in it).
UINavigationItem *item = scrollView.navbar.topItem;
UIToolbar *authorTools = (UIToolbar *)[item.rightBarButtonItem customView];
CGRect r = authorTools.frame;
r.size.width = 18;
r.origin.x += 12;
CGSize popoverSize = CGSizeMake(300.f, 500.f);
MGSettingsView *settingsView = [[MGSettingsView alloc] initWithSize:popoverSize];
UIPopoverController *poctl = [[UIPopoverController alloc] initWithContentViewController:settingsView];
settingsView.popover = poctl;
poctl.delegate = self;
poctl.popoverContentSize = popoverSize;
[poctl presentPopoverFromRect:r inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[settingsView release];
如果这不是您要的内容,那么我想改一下您的问题.:)
If this isn't what you're asking for you'd better rephrase your question I think. :)
这篇关于UIPopoverController更改UIPopoverArrowDirection的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!