问题
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