借助刮刮和获胜示例显示刮刮卡效果

时间:2013-12-02 08:15:44

标签: iphone objective-c xcode

我是ios developpement的新手。如果优惠券号码可见,我需要在划痕后为iPhone应用程序显示刮刮卡效果我需要显示提醒消息我该怎么做?.i从{{下载示例代码3}}并且我已经完成了在屏幕下方显示并且划痕也可以正常工作

如果UILabel文本可见,我想显示警告信息我该怎么做?

我附加了屏幕截图供您参考 enter image description here

enter image description here

enter image description here

3 个答案:

答案 0 :(得分:2)

我找到了非常好的Github示例请看看这个和恭维作为标准你需要希望这对你有帮助我的朋友。

CGScratch这与您想要应用的内容相同。

enter image description here

检查代码并检查数字的可见区域否则检查过程图像是否已被删除,如果删除则显示警告。

答案 1 :(得分:2)

一个简单的UIImageView子类,允许您的UIImageView成为刮刮卡。

storyboard设置的xib自定义类中,代表您的临时图像UIImageView。更改ScratchCardImageViewlineType以更改划痕线的外观。

下载example

enter image description here

斯威夫特3:

lineWidth

<强>更新

使用此解决方案,将仅在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() } } 范围内跟踪触摸事件。如果您需要在刮刮卡之外启动触摸事件,请参阅ScratchCardTouchContainer示例

答案 2 :(得分:1)