简体   繁体   English

UITableViewCell 阴影在滚动时消失(iOS 13)

[英]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).我在我的应用程序中发现了一些回归,我很确定现在才在 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.它曾经工作得很好,但现在我们开始看到一些奇怪的东西......我们添加到每个单元格的阴影突然在 tableview 滚动上自行消失。

图片说明

The app uses UITableView and inside delegate method willDisplayCell: we call this code:该应用程序使用UITableView和内部委托方法willDisplayCell:我们调用此代码:

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.我尝试使用view.layer.zPositionview.backgroundColor=UIColor.clearColor没有运气。

Does anyone knows what's going on there?有谁知道那里发生了什么?

Update:更新:

This same issue happens also in UICollectionView. UICollectionView 也会出现同样的问题。

Answering the comments:回复评论:

  1. changing UIUserInterfaceStyle in plist to "Light" didn't help.将 plist 中的UIUserInterfaceStyle更改为“Light”并没有帮助。
  2. set shadowColor at the end of the method - didn't help.在方法结束时设置 shadowColor - 没有帮助。
  3. adding shadow in cellforrow instead of willdisplaycell - didn't help在 cellforrow 而不是 willdisplaycell 中添加阴影 - 没有帮助

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 .我发现问题是由于某种原因,当显示单元格时, layer.clipsToBound 被重置为 True All you need to do to fix it is when the tableViewDelegate calls for viewWillDisplayCell set the layer.clipsToBound = false修复它所需要做的就是当tableViewDelegate调用viewWillDisplayCell设置layer.clipsToBound = false

That worked for me.这对我有用。

Try to add shadow in awakefrom nib of the collectionview cell as bellow code.尝试在 collectionview 单元格的 awakefrom nib 中添加阴影,如下所示。

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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