Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove the focus shadows from a UIView in a UICollectionView in swift?

I'm working on a tvOS project in swift and have a horizontally aligned UICollectionView where each UICollectionViewCell is a custom UIView consisting of a UIImageView and a Label below it. So my UICollectionView looks like this:

| UIImageView |   | UIImageView |
| Label       |   | Label       |  

I also wanted the image to grow/shrink as the particular view gained and lost focus. In my collection view I added the code

func collectionView(collectionView: UICollectionView, canFocusItemAtIndexPath indexPath: NSIndexPath) -> Bool {
        return true
}

And in my custom cell class I have the line

imageView.adjustsImageWhenAncestorFocused = true;

So this somewhat works, although with 2 problems.

It seems all the views in the collection have a weird shadow under them, even when they're not focused. And then when they are focused, the image grows as expected, but it has another shadow under it. You can see what I mean here:

this screenshot

The first item in the collection has the focus

How do I get rid of them? I've tried all of these but none of them seem to work

contentView.layer.shadowOpacity = 0.0  // My imageView is a subview of this
contentView.layer.shadowColor = UIColor.clearColor().CGColor
imageView.layer.shadowOpacity = 0.0
imageView.layer.shadowColor = UIColor.clearColor().CGColor
like image 924
Programmer Unextraordinair Avatar asked Jan 08 '16 16:01

Programmer Unextraordinair


Video Answer


1 Answers

It's not possible right now. I forwarded this question to Apple, and the response was: https://forums.developer.apple.com/message/105045#105045

like image 119
JackPearse Avatar answered Nov 03 '22 23:11

JackPearse