ios – Popover控制背景颜色奇怪的行为

ios – Popover控制背景颜色奇怪的行为,第1张

概述所以在我的应用程序中,我有一个带有嵌入式导航控件的d出控件.在导航堆栈的不同部分,我希望d出窗口是不同的颜色,具体取决于用户的位置.奇怪的是有时候设置popover背景颜色使得这个看起来很糟糕的盒子,有时它不会.它看起来像这样: 这是我想要的外观: 似乎如果我在显示d出窗口之前更改背景颜色,它似乎正常工作并转换,但如果我在显示之前没有设置d出窗口颜色,则在显示它具有框效果后更改它.我还注意到其他似 所以在我的应用程序中,我有一个带有嵌入式导航控件的d出控件.在导航堆栈的不同部分,我希望d出窗口是不同的颜色,具体取决于用户的位置.奇怪的是有时候设置popover背景颜色使得这个看起来很糟糕的盒子,有时它不会.它看起来像这样:

这是我想要的外观:

似乎如果我在显示d出窗口之前更改背景颜色,它似乎正常工作并转换,但如果我在显示之前没有设置d出窗口颜色,则在显示它具有框效果后更改它.我还注意到其他似乎随机发生的情况,但我无法解释导致它的原因(我的真实应用程序比这个演示要复杂得多).这是相关代码:

- (IBAction)buttonpressed:(ID)sender {    UIVIEwController *vc = [[UIVIEwController alloc] init];    UIbutton *b = [[UIbutton alloc] init];    [b addTarget:self action:@selector(innerbuttonpressed) forControlEvents:UIControlEventtouchUpInsIDe];    [b setTitle:@"button" forState:UIControlStatenormal];    [b setTitlecolor:[UIcolor bluecolor] forState:UIControlStatenormal];    [b setFrame:CGRectMake(0,100,100)];    [vc.vIEw addSubvIEw:b];    _innerNav = [[UINavigationController alloc] initWithRootVIEwController:vc];    _popOver = [[UIPopoverController alloc] initWithContentVIEwController:_innerNav];    //If this line is here,everything works fine    _popOver.backgroundcolor = [UIcolor yellowcolor];    [_popOver presentPopoverFrombarbuttonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];    //If this line is here (and the above line is commented out),the Transition will look wrong    //_popOver.backgroundcolor = [UIcolor yellowcolor];}-(voID)innerbuttonpressed {    _controller = [[UIVIEwController alloc] init];    UIbutton *b = [[UIbutton alloc] init];    [b addTarget:self action:@selector(test) forControlEvents:UIControlEventtouchUpInsIDe];    [b setTitle:@"Make Purple" forState:UIControlStatenormal];    [b setTitlecolor:[UIcolor bluecolor] forState:UIControlStatenormal];    [b setFrame:CGRectMake(0,200,200)];    [_controller.vIEw addSubvIEw:b];    [_popOver setBackgroundcolor:[UIcolor orangecolor]];    [_innerNav pushVIEwController:_controller animated:YES];}-(voID)test{    _popOver.backgroundcolor = [UIcolor purplecolor];}

知道是什么导致了这个问题吗?什么步骤安全地更新d出窗口的背景颜色而不进入这种状态?我有一个完整的项目来证明这个问题,我认为你可以将项目附加到问题上,但显然你不能.如果有人想要它我可以在某个地方托管它.

解决方法 在查看了您的示例项目,Apple的 “Popover Controllers in iOS”示例项目,仔细阅读 Apple’s Documentation,并尝试了一些不同的事情后,我得出了以下观察结果:

> UIPopoverController仅在显示backgroundcolor属性的有效值时才显示此奇怪行为.由此我猜测,因为UIPopoverController的backgroundcolor属性默认为nil,所以必须使用与backgroundcolor属性有效时不同的绘图代码.
>触发某种重绘(e.x.设置popoverContentSize)将使彩色框叠加消失(看起来它会剪切彩色图层).

结论:暂时我会在呈现UIPopoverController之前设置backgroundcolor,然后根据需要更新它.如果这不是一个选项,请尝试更新UIPopoverController,使其重绘(作为注释:我无法让它看起来很好,而且看起来很糟糕).最后,我会report it as a bug去苹果.

我希望这有帮助.

总结

以上是内存溢出为你收集整理的ios – Popover控制背景颜色奇怪的行为全部内容,希望文章能够帮你解决ios – Popover控制背景颜色奇怪的行为所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存