简体   繁体   中英

UITableViewCell shadow disappears on scroll (iOS 13)

I found some regression in my app which I'm pretty sure only started now on Xcode 11.3.1 (iOS 13).

It used to work great but now we started seeing something weird.. the shadows we add to each cell suddenly disappears by themselves on tableview scroll.

图片说明

The app uses UITableView and inside delegate method willDisplayCell: we call this code:

dispatch_async(dispatch_get_main_queue(), ^{
    view.layer.cornerRadius = 4.0f;
    view.layer.borderWidth = 1.0f;
    view.layer.borderColor = [UIColor clearColor].CGColor;

    view.layer.shadowColor = shadowColor != nil ? shadowColor.CGColor : [[UIColor lightGrayColor] CGColor];
    view.layer.shadowOffset = CGSizeMake(0, 2.0f);
    view.layer.shadowRadius = 2.0f;
    view.layer.shadowOpacity = 1.0f;
    view.layer.masksToBounds = NO;
    view.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds cornerRadius:view.layer.cornerRadius].CGPath;
});

I tried to play with view.layer.zPosition and with view.backgroundColor=UIColor.clearColor with no luck.

Does anyone knows what's going on there?

Update:

This same issue happens also in UICollectionView.

Answering the comments:

  1. changing UIUserInterfaceStyle in plist to "Light" didn't help.
  2. set shadowColor at the end of the method - didn't help.
  3. adding shadow in cellforrow instead of willdisplaycell - didn't help

I was having trouble with this too. What I found to be the problem is for some reason when the cell will be displayed, the layer.clipsToBound is reset to True . All you need to do to fix it is when the tableViewDelegate calls for viewWillDisplayCell set the layer.clipsToBound = false

That worked for me.

Try to add shadow in awakefrom nib of the collectionview cell as bellow code.

override func awakeFromNib() {
    super.awakeFromNib()
    view.layer.shadowColor = UIColor.red.cgColor
    view.layer.shadowOffset = CGSize(width: 0, height: 2)
    view.layer.shadowRadius = 2
    view.layer.shadowOpacity = 1
    view.layer.masksToBounds = false
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM