簡體   English   中英

在圖像視圖上快速創建傾斜的切割

[英]Create slanted cut on image view swift

我一直在互聯網上四處逛逛,但找不到在快速顯示的圖像視圖上進行傾斜切割的好方法。

這就是我想要的
在此處輸入圖片說明

如您所見,我想傾斜在背景中看到的圖像視圖。 如果有人有任何想法或解決方案,將不勝感激。

屬性:

fileprivate var headerView: PostHeaderView!
fileprivate var headerMaskLayer: CAShapeLayer!

在viewDidLoad()中:

headerMaskLayer = CAShapeLayer()
    headerMaskLayer.fillColor = UIColor.black.cgColor
    headerView.layer.mask = headerMaskLayer

    updateHeaderView()

然后使用此功能:

func updateHeaderView() {
    let effectiveHeight = Storyboard.tableHeaderHeight - Storyboard.tableHeaderCutAway / 2

    var headerRect = CGRect(x: 0, y: -effectiveHeight, width: tableView.bounds.width, height: Storyboard.tableHeaderHeight)

    headerView.logoImageView.alpha = 0

    if tableView.contentOffset.y < -effectiveHeight {
        headerRect.origin.y = tableView.contentOffset.y
        headerRect.size.height = -tableView.contentOffset.y + Storyboard.tableHeaderCutAway/2

        let final: CGFloat = -100
        let alpha =  min((tableView.contentOffset.y + effectiveHeight) / final, 1)
        headerView.logoImageView.alpha = alpha
    }

    headerView.frame = headerRect

    // cut away
    let path = UIBezierPath()
    path.move(to: CGPoint(x: 0, y: 0))
    path.addLine(to: CGPoint(x: headerRect.width, y: 0))
    path.addLine(to: CGPoint(x: headerRect.width, y: headerRect.height))
    path.addLine(to: CGPoint(x: 0, y: headerRect.height - Storyboard.tableHeaderCutAway))
    headerMaskLayer?.path = path.cgPath
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM