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

问题描述 投票:5回答:3

我是ios developpement的新手。如果优惠券号码可见,我需要在划痕后为iPhone应用程序显示刮刮卡效果我需要显示警告消息我该怎么做?.i从 iPhone - Scratch and Win Example下载示例代码我也有完成显示屏幕下方和划痕也很好

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

我附上了截图供您参考

iphone objective-c xcode
3个回答
2
投票

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

CGScratch这是你想要应用的相同的东西。

检查代码并检查数字的可见区域否则检查chescration overImage被严重删除如果删除然后显示警报。


2
投票

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

在你的storyboardxib中设置你的UIImageView的自定义类,代表你的ScratchCardImageView的划痕图像。更改lineTypelineWidth以更改划痕线的外观。

下载example

enter image description here

斯威夫特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示例


© www.soinside.com 2019 - 2024. All rights reserved.