ios – UIPopover presentFromBarButton离开中心

ios – UIPopover presentFromBarButton离开中心,第1张

概述我在一个项目中注意到,由于某种原因,一个d出窗口位于右侧的按钮项目上的位置似乎偏离了右侧.我已经尝试使用UIButton的自定义视图,然后从该按钮显示popover,但popover似乎忽略showFromRect,如果我实际提供它的“居中”值. 这背后的代码很简单: - (void)viewDidLoad { [super viewDidLoad]; UIBarButtonI 我在一个项目中注意到,由于某种原因,一个d出窗口位于右侧的按钮项目上的位置似乎偏离了右侧.我已经尝试使用UIbutton的自定义视图,然后从该按钮显示popover,但popover似乎忽略showFromrect,如果我实际提供它的“居中”值.

这背后的代码很简单:

- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];     UIbarbuttonItem *button = [[UIbarbuttonItem alloc] initWithImage:[UIImage imagenamed:@"share"] style:UIbarbuttonItemStylePlain target:self action:@selector(shareTap:)];     self.navigationItem.rightbarbuttonItem = button;}- (voID)shareTap:(UIbarbuttonItem *)button {    self.popover = [[UIPopoverController alloc] initWithContentVIEwController:[[UIVIEwController alloc] init]];    [self.popover presentPopoverFrombarbuttonItem:button permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];}

现在,如果我转到使用内部按钮,如上所述,我看到类似的行为(注意颜色变化,所以图像显示).

这个代码还是比较简单的:

- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    UIbutton *innerbutton = [[UIbutton alloc] initWithFrame:CGRectMake(0,22,22)];    [innerbutton setimage:[UIImage imagenamed:@"share"] forState:UIControlStatenormal];    [innerbutton addTarget:self action:@selector(shareTap:) forControlEvents:UIControlEventtouchUpInsIDe];    self.navigationItem.rightbarbuttonItem = [[UIbarbuttonItem alloc] initWithCustomVIEw:innerbutton];;}- (voID)shareTap:(UIbutton *)button {    self.popover = [[UIPopoverController alloc] initWithContentVIEwController:[[UIVIEwController alloc] init]];//    CGRect bottomCenter = CGRectMake(button.frame.size.wIDth / 2,button.frame.size.height,1,1);    CGRect bottomCenter = CGRectMake(2,1);    [self.popover presentPopoverFromrect:bottomCenter inVIEw:button permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];}

请注意,不用使用实际的中心,我使用了任意值,如果我使用1或0,则d出窗口左对齐.任何大于一个都是正确的对齐.

我搜索了一些类似的问题,但我似乎找不到有同样问题的人.关于什么导致这个或如何避免的任何想法将不胜感激.我唯一可以猜到的是,由于它靠近边缘,苹果做了一些定位巫术,迫使它成为他们想要的地方.问题是,右上角的按钮似乎是一个非常标准的下拉位置.

编辑:我已经确认,在本地邮件应用程序的“新消息”图标上长按可能会发生同样的情况.

编辑2:我能够与苹果确认这是一个问题.在最新的版本之一(我不记得我认为的9个中的哪一个),他们就这样做了,所以你可以手动设置这个.默认的行为仍然是错误的我相信(我没有尝试过一段时间),但是您可以使用CGRect偏移方法使其正常工作,如果你这么倾向.

解决方法 尝试这个自定义Popover Controller – WYPopoverController( https://github.com/nicolaschengdev/WYPopoverController)来修复问题. 总结

以上是内存溢出为你收集整理的ios – UIPopover presentFromBarButton离开中心全部内容,希望文章能够帮你解决ios – UIPopover presentFromBarButton离开中心所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1112750.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存