ios - 是否可以在透明部分标题后面 "hide"UITableViewCell?

标签 ios swift xcode

我的 iOS 项目中有一个 tableview,它使用图像作为背景。图像不滚动,它是静态的。因此,我也有透明的单元格和节标题。现在我的问题是如何使(透明)单元格在(也是透明的)部分标题后面“隐藏”或“消失”?
是否可以?

Screenshot

最佳答案

在您的自定义单元格上

public func maskCell(fromTop margin: CGFloat) {
    layer.mask = visibilityMask(withLocation: margin / frame.size.height)
    layer.masksToBounds = true
}

private func visibilityMask(withLocation location: CGFloat) -> CAGradientLayer {
    let mask = CAGradientLayer()
    mask.frame = bounds
    mask.colors = [UIColor.white.withAlphaComponent(0).cgColor, UIColor.white.cgColor]
    let num = location as NSNumber
    mask.locations = [num, num]
    return mask
}

和你 ViewController UIScrollViewDelegate
func scrollViewDidScroll(_ scrollView: UIScrollView) {
     for cell in self.lessonsTableView.visibleCells {
         let paddingToDisapear = CGFloat(25)

         let hiddenFrameHeight = scrollView.contentOffset.y + paddingToDisapear - cell.frame.origin.y
         if (hiddenFrameHeight >= 0 || hiddenFrameHeight <= cell.frame.size.height) {
             if let customCell = cell as? LessonTableViewCell {
                 customCell.maskCell(fromTop: hiddenFrameHeight)
             }
         }

     }
 }

关于ios - 是否可以在透明部分标题后面 "hide"UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49498292/

相关文章:

iOS:不同的调试和发布常量,objective-c

ios - Realm 更新数据 + DispatchQueue

xcode - 当按下 UIBarButton 时,UIView 会回到原来的框架

iphone - iOS 记录器库

ios - ionic/cordova 项目中的 Xcode 设备列表为空

ios - AVPlayerStatusFailed 和错误代码 "Cannot Decode"

ios - 无需提交至应用商店即可开发个人 iOS 应用

ios - 如何从另一个 View 中关闭 Popover?

ios - 更改 STPPaymentCardTextField 的布局

swift - 获取选定的 Finder 文件