我是ios开发的新手。我需要在划痕后显示iPhone应用程序的划痕效果,如果优惠券号码可见,我需要显示警告消息,我该如何做?我已经从 iPhone - Scratch and Win Example下载了示例代码,并且我已经完成了下面的屏幕显示,划痕也很好
如果UILabel文本可见,我想要显示警告消息,我该怎么做?
我附上了截图供你参考



发布于 2013-12-02 17:32:51
我发现了非常好的Github例子,请看看这个,并实现你需要的标准,希望这对你有帮助,我的朋友。
CGScratch这也是你想要应用的东西。

检查代码并检查数字的可见区域,否则检查overImage是否已完全删除,如果未删除,则显示警报。
发布于 2016-12-10 00:52:03
一个简单的UIImageView子类,它允许您的UIImageView成为scratch卡片。
在您的storyboard或xib中,将表示临时图像的UIImageView的自定义类设置为ScratchCardImageView。更改lineType或lineWidth以更改暂存线的外观。
下载example

Swift 3:
import UIKit
class ScratchCardImageView: UIImageView {
private var lastPoint: CGPoint?
var lineType: CGLineCap = .square
var lineWidth: CGFloat = 20.0
override func awakeFromNib() {
super.awakeFromNib()
isUserInteractionEnabled = true
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else {
return
}
lastPoint = touch.location(in: self)
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first, let point = lastPoint else {
return
}
let currentLocation = touch.location(in: self)
eraseBetween(fromPoint: point, currentPoint: currentLocation)
lastPoint = currentLocation
}
func eraseBetween(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()
}
}已更新
使用此解决方案,将仅在UIImageView边界内跟踪触摸事件。如果您需要在暂存卡之外启动触摸事件,请参阅ScratchCardTouchContainer示例
发布于 2013-12-02 17:43:40
您还可以查看此github教程中的scratch:
https://stackoverflow.com/questions/20323589
复制相似问题