ios - 将 iOS 7 样式模糊应用到 TableView 部分标题

标签 ios cocoa-touch uitableview graphics

我想在表格 View 的表格部分标题中应用模糊效果,类似于您在控制中心向上拖动时看到的效果。我查看了一些 GitHub 存储库,例如 iOS-blur 和 LiveFrost,但它们似乎不起作用。它们实际上并没有模糊滚动经过部分标题的表格单元格,但它们模糊了部分 View 的内容,这正是我想要避免的。

有什么建议吗?

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UITableViewCell *headerView = [tableView dequeueReusableCellWithIdentifier:@"SetSelectionHeaderCell"];

    headerView.backgroundColor = [UIColor clearColor];
    //LFGlassView *glassView = [[LFGlassView alloc] initWithFrame:headerView.frame];
    JCRBlurView *glassView = [JCRBlurView new];
    [glassView setFrame:headerView.frame];
    [glassView setBlurTintColor:[UIColor blackColor]];
    [headerView addSubview:glassView];

    [headerView sendSubviewToBack:glassView];


    return headerView;
}

最佳答案

您的问题是您将 blurView 添加为 headerView 的 subview ,但 headerView 的 backgroundColor 默认为白色,因此不透明。为了看到 headerView 背后的 View ,您需要使 headerView 透明。您可以通过设置来做到这一点

headerView.backgroundColor = [UIColor clearColor]

iOS-Blur View 通过模糊其背后的 View 来工作。因此,您看到 headerView 的标题标签模糊不清的原因是因为 blurView 在添加标签后作为 subview 添加到 headerView 中。这会将 blurView 放在标签前面,作为最顶层的 subview 。在将模糊 View 添加为 subview 后,您需要将它一直发送到后面。

[headerView sendSubviewToBack:blurView];

如果您使 headerView 透明并在后面添加 blurView,它应该可以按您希望的方式工作。

结果应该是这样的:

this

我还应该注意,如果您在每次将它作为 tableView 单元格出列时向 headerView 添加 subview , subview 将会累积。

关于ios - 将 iOS 7 样式模糊应用到 TableView 部分标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23400945/

相关文章:

ios - 有没有办法在 iOS 中设置推送通知的类型?

iphone - TableView 中的复选框单元格 : User can't check it

iphone - 在 iOS 6 中以编程方式获取通话记录

cocoa-touch - 在后台接收 UIPasteboard (generalPasteboard) 通知

objective-c - TableView 单元格在修饰时不会失去高亮显示

iPhone - iPhone 无法振动

ios - Restkit-无法在 NSManagedObject 类上调用指定的初始化程序

iOS 6 : Need to add an image and text to screenshot's footer

ios - 点击表格 View 单元格时显示图片

ios - Kingfisher 将数据缓存在 RAM 中