UIImageView Mask Layer not coming from corners Until Scroll PageViewController First time

只愿长相守 提交于 2019-12-02 03:36:34

I solved issue with

    path.move(to: .zero)
    /* THIS HELPLS ME */ path.addLine(to: CGPoint(x: 0  , y: self.imgView.frame.height  -  imageCutAwayPart / 2 ))
    path.addLine(to: CGPoint(x: self.imgView.frame.width   , y: self.imgView.frame.height - imageCutAwayPart))
    path.addLine(to: CGPoint(x: self.imgView.frame.width, y: 0))

But I don't understand why I need to move CGPoint(x: 0 , y: self.imgView.frame.height - imageCutAwayPart / 2 ) instead of this CGPoint(x: 0 , y: self.imgView.frame.height)

If any one know this please post as answer I will surely accept the answer

EDIT

There was silly but smart mistake in Storybaord

Mistake was there is UIView which contains Label shown in screenshot. The Part visible is is the UIView I thought it masking is not working properly. Still there is issue that very first time in pageview controller mask is not proper but after scroll one time it is perfect.

EDIT2 Thanks to @DonMag

Following is working solution for every case

class CutOfImageView:UIImageView {
    let imageCutAwayPart:CGFloat = 80
    let maskLayer = CAShapeLayer()

    override func layoutSubviews() {
        super.layoutSubviews()
        self.setupImageCutPath()
        self.layer.mask = self.maskLayer

    }

    private func setupImageCutPath () {
        let path = UIBezierPath()
        path.move(to: .zero)
        path.addLine(to: CGPoint(x: 0  , y: self.frame.height ))
        path.addLine(to: CGPoint(x: self.frame.width   , y: self.frame.height - imageCutAwayPart))
        path.addLine(to: CGPoint(x: self.frame.width, y: 0))
        path.close()
        self.maskLayer.path = path.cgPath



    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!