gpt4 book ai didi

uitableview - UITableView 背景上的 UIVisualEffectView

转载 作者:行者123 更新时间:2023-12-04 14:12:30 33 4
gpt4 key购买 nike

我正在创建一个 UITableViewController(在 UINavigationController 的根部)并在另一个 View Controller 之上以模态方式呈现它。我让它在一定程度上工作,这样当 View 加载并调用 viewDidAppear 时,视觉效果看起来不错。但是在 viewDidAppear 之后,视觉效果消失了,tableview 有一个白色背景。

在我展示的 UITableViewController 中,我在 viewDidLoad 中添加了这个:

if (NSClassFromString(@"UIVisualEffectView") && !UIAccessibilityIsReduceTransparencyEnabled()) {
self.tableView.backgroundColor = [UIColor clearColor];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
[blurEffectView setFrame:self.tableView.frame];

self.blurView = blurEffectView;
self.tableView.backgroundView = self.blurView;
}

我也实现了这一点,以确保单元格具有清晰的背景:
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if (NSClassFromString(@"UIVisualEffectView") ) {
cell.backgroundColor = [UIColor clearColor];
}
}

我也设置了 cell.backgroundColor = [UIColor clearColor]在 tableView 的 cellForRowAtIndexPath:但这也无济于事。

同样,当 View 加载时我得到了正确的效果,但它一旦出现在屏幕上就会失去模糊背景。任何想法可能会出错?我还尝试将 blueEffectView 作为属性保留在我的 View Controller 中,但没有运气

最佳答案

你在使用 Storyboard吗?

选择模态使用的 View Controller (或者如果它包装在另一个 VC 中,则选择包装器)并将 Presentation 组合框设置为“Over Full Screen”或“Over Current Context”。 (我实际上不知道有什么区别,他们似乎都在做同样的事情。)

Screenshot of Xcode

这样做之后,您的模糊效果应该是 Just Work™。另外,我认为这是 iOS 8 中的新功能,我还没有在 iOS 7 中测试过。

关于uitableview - UITableView 背景上的 UIVisualEffectView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26015532/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com