加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

UIPopoverController backgroundColor在显示时导致flash

发布时间:2020-12-15 07:29:34 所属栏目:百科 来源:网络整理
导读:我在我的应用程序中使用新的(在iOS 7中)UIPopoverController.backgroundColor设置来根据需要更改我的弹出窗口的颜色,但我发现使用此设置会在我打开我的时候导致颜色更改的“闪烁”弹出窗口 – 在大约半秒钟内从默认的半透明白色开始,逐渐消失到我选择的颜色.
我在我的应用程序中使用新的(在iOS 7中)UIPopoverController.backgroundColor设置来根据需要更改我的弹出窗口的颜色,但我发现使用此设置会在我打开我的时候导致颜色更改的“闪烁”弹出窗口 – 在大约半秒钟内从默认的半透明白色开始,逐渐消失到我选择的颜色.这是不希望的;它应该只是我打开它时设置的颜色.

文件说明:

Use this property to customize the background color of your popover. Changing the value of this property while the popover is visible triggers an animated changeover to the new color. The default value of this property is nil,which corresponds to the default background color.

但是,即使我在我的应用程序打开时设置它并且不再设置它,每次打开任何弹出窗口时它仍会闪烁.

我愿意使用UIPopoverBackgroundView,但我不确定它是否允许我即时更改背景颜色,因为它似乎是一个静态解决方案,只需更改应用程序中所有弹出窗口的样式.在此先感谢您的任何建议.

编辑(代码):

当我的主视图控制器被加载并准备其余的UI(这是许多popover inits之一):

fileOptionsController = [[FileOptionsViewController alloc] initWithNibName:@"FileOptionsViewController" bundle:nil];
fileOptionsController.delegate = self;

self.fileOptionsPopoverController = [[UIPopoverController alloc] initWithContentViewController:fileOptionsController];
[popoverControllers addObject:self.fileOptionsPopoverController];

在我的popovers初始化之后,我正在运行它(仍然在主init代码中),目的是在设置backgroundColor和交互之间进行长时间延迟测试(注意:更改alpha没有任何效果,当设置为1时仍然会发生):

for (UIPopoverController *po in popoverControllers) {
    [po setBackgroundColor:[UIColor colorWithWhite:0.3f alpha:0.90f]];
}

然后,当用户点击按钮以显示弹出框时,会调用此方法:

- (void)showPopover:(UIPopoverController *)popover from:(UIButton *)btn {
    [popover presentPopoverFromRect:CGRectMake(btn.frame.origin.x + 5.0f,btn.frame.origin.y - 1.0f,btn.frame.size.width,btn.frame.size.height) inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}

挺直的.这些是访问此弹出窗口或任何弹出窗口的唯一相关位置,除非在已经显示的情况下将其解除.

解决方法

我解决了这个问题,在更改backgroundColor然后再次呈现之前解除了popover:

[popover dismissPopoverAnimated:NO];

if ([popover respondsToSelector:@selector(backgroundColor)]) {
    popover.backgroundColor = [UIColor someColor];         
}

[popover setContentViewController:viewController animated:NO];
[popover setPopoverContentSize:CGSizeMake(320.0f,480.0f) animated:NO];

[popover presentPopoverFromRect:popoverRect
                         inView:self.view
       permittedArrowDirections:UIPopoverArrowDirectionRight
                       animated:NO];

这样做会再次显示弹出窗口,您将看不到任何不需要的过渡效果.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读