Scratch Card effect in Swift 3

泪湿孤枕 提交于 2019-12-23 04:52:58

问题


I am trying to implement a Scratch Card effect in Swift 3 for my app, I found some examples but they're on Objective C (show scratch-card effect with the help of using scratch and win example)

In essence user swipes with finger on an image and reveals another image below their finger as they swipe.

Any one knows how to do this in Swift 3? Any help greatly appreciated


回答1:


You can use ScratchCard library. It has simple API, but I don't know is it Swift 3 compatible. Anyway, you can rewrite it or check its implementation.




回答2:


Check this Swift 3 example of ScratchCardImageView

A simple UIImageView subclass that allows your UIImageView become a scratch card.




回答3:


I found a library that suits your requirement. It is Swift 3 compatible. Try this SRScratchView

ScreenShot

 var lineType: CGLineCap = .round
 var lineWidth: CGFloat = 30.0

 func scrachBetween(fromPoint: CGPoint, currentPoint: CGPoint) {

        UIGraphicsBeginImageContext(self.frame.size)

        image?.draw(in: self.bounds)

        let path = CGMutablePath()
        path.move(to: fromPoint)
        path.addLine(to: currentPoint)

        let context = UIGraphicsGetCurrentContext()!
        context.setShouldAntialias(true)
        context.setLineCap(lineType)
        context.setLineWidth(lineWidth)
        context.setBlendMode(.clear)
        context.addPath(path)

        context.strokePath()

        image = UIGraphicsGetImageFromCurrentImageContext()


        UIGraphicsEndImageContext()
    }


来源:https://stackoverflow.com/questions/40610628/scratch-card-effect-in-swift-3

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