Kev*_*lia 4 objective-c ios uipopover ios7
所以在我的应用程序中,我有一个带有嵌入式导航控件的弹出控件.在导航堆栈的不同部分,我希望弹出窗口是不同的颜色,具体取决于用户的位置.奇怪的是有时候设置popover背景颜色使得这个看起来很糟糕的盒子,有时它不会.它看起来像这样:

这是我想要的外观:

似乎如果我在显示弹出窗口之前更改背景颜色,它似乎正常工作并转换,但如果我在显示之前没有设置弹出窗口颜色,则在显示它具有框效果后更改它.我还注意到其他似乎随机发生的情况,但我无法解释导致它的原因(我的真实应用程序比这个演示要复杂得多).这是相关代码:
- (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,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,0,200,200)];
[_controller.view addSubview:b];
[_popOver setBackgroundColor:[UIColor orangeColor]];
[_innerNav pushViewController:_controller animated:YES];
}
-(void)test{
_popOver.backgroundColor = [UIColor purpleColor];
}
Run Code Online (Sandbox Code Playgroud)
知道是什么导致了这个问题吗?什么步骤安全地更新弹出窗口的背景颜色而不进入这种状态?我有一个完整的项目来证明这个问题,我认为你可以将项目附加到问题上,但显然你不能.如果有人想要它我可以在某个地方托管它.
在看了你的示例项目,Apple的"iOS中的Popover控制器"示例项目,仔细阅读Apple的文档,并尝试了一些不同的事情,我得到了以下观察:
UIPopoverController唯一的展品时,它呈现不为有效值这个奇怪的行为backgroundColor性质.由此我猜测,因为默认情况下它UIPopoverController的backgroundColor属性nil必须使用与backgroundColor属性有效时不同的绘图代码.popoverContentSize)将使彩色框叠加消失(看起来它会剪切彩色图层).结论:暂时我会在呈现backgroundColor之前设置一个UIPopoverController,然后根据需要更新它.如果这不是一个选项,请尝试更新UIPopoverController它重绘(作为一个注释:我无法让它看起来很好,而且看起来很hacky).最后,我会将其报告为苹果的一个错误.
我希望这有帮助.
| 归档时间: |
|
| 查看次数: |
1659 次 |
| 最近记录: |