【问题标题】:show scratch-card effect with the help of using scratch and win example在使用刮刮乐示例的帮助下显示刮刮卡效果
【发布时间】:2018-01-05 14:40:49
【问题描述】:

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

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

我已附上屏幕截图供您参考

【问题讨论】:

  • 您好,您找到解决方案了吗?
  • 你好@Ravindhiran 你找到这个问题的答案了吗?如果你找到了,请帮助我,我有和你一样的问题。请帮帮我。

标签: iphone objective-c xcode


【解决方案1】:

我找到了非常好的 Github 示例,请看一下这个并按照您的需要暗示,希望这对您有帮助,我的 Frnd。

CGScratch这和你想申请的一样。

查看代码并检查 Number 的可见区域 else check che scration overImage is tally remove or not if remove then show Alert.

【讨论】:

    【解决方案2】:

    一个简单的UIImageView 子类,可以让您的UIImageView 成为一张刮刮卡。

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

    下载example

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

    【讨论】:

      【解决方案3】:

      您也可以查看此 github 教程以获取暂存信息:

      1. https://github.com/SebastienThiebaud/STScratchView
      2. https://github.com/moqod/iOS-Scratch-n-See

      【讨论】:

      • 如何获取划伤面积和可划伤面积?
      猜你喜欢
      • 1970-01-01
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多