What is UITableView separatorEffect property for?

2019-03-18 15:30发布

New in iOS 8 is a separatorEffect property, to which you are allowed to assign a UIVisualEffect. Has anyone figured out what this is for? I've tried it and I don't see it as having any, uh, visual effect.

3条回答
Juvenile、少年°
2楼-- · 2019-03-18 15:54

As both answers have said, the only effect this is intended for is a vibrancy effect when the background of the table is a blur effect. The difference with and without the effect can be subtle:

enter image description here

enter image description here

查看更多
Luminary・发光体
3楼-- · 2019-03-18 16:04

I was wondering the exact same thing so I put a Github project together for anyone facing the same issue.

The basic idea is that if your tableView's backgroundView consists of a UIVisualEffectView with a blur effect, then setting the seperatorEffect to a Vibrant Effect with the same blur as the UIVisualEffectView will produce the effect we see in Notification Center where the separators seem transparent.

Something like this:

tableView.separatorEffect = UIVibrancyEffect(forBlurEffect: blurredBackgroundView.blurView.effect as UIBlurEffect)

will produce a table view like this:

enter image description here

查看更多
在下西门庆
4楼-- · 2019-03-18 16:09

Start by watching session 419 from this year's WWDC: "Advanced Graphics and Animations for iOS Apps", they explain how the new visual effect classes work.

I have a UITableViewController in my app that I use as a modal popover. The parent view controller gets blurred by a UIVisualEffectView with a UIBlurEffect, while the table view separators have a UIVibrancyEffect set as effect. On my iPhone 5, it looks like this: Screenshot of modal popover

This is what that same view looks like if separatorEffect is nil: enter image description here

You could, of course, apply a UIBlurEffect to the separators, but that would most likely just be a waste of resources.

Note: Don't actually do what I did in this example. UIVibrancyEffect is very expensive. Just applying a UIVibrancyEffect to this table view's separators caused my app to miss the 60 FPS target on an iPhone 5.

Also note that the Reduce Transparency option under the Accessibility section in Settings.app is a thing and causes UIBlurEffects to be rendered as a solid color. Always check before instancing any UIVisualEffects. Here's some keywords for you to google: UIAccessibilityIsReduceTransparencyEnabled() and UIAccessibilityReduceTransparencyStatusDidChangeNotification

Hope I could help you.

查看更多
登录 后发表回答