美文网首页
iOS刮奖效果

iOS刮奖效果

作者: Demonboy | 来源:发表于2017-07-04 10:24 被阅读315次
    这是swift
    
    override func viewDidLoad() {
    
    super.viewDidLoad()
    
    view.addSubview(tip)
    
    view.addSubview(codeImageView)
    
    }
    
    lazy var tip:UILabel= {
    
    let tip =UILabel(frame:CGRect(x:0, y:64, width:200, height:200))
    
    tip.text="恭喜"
    
    tip.numberOfLines=0
    
    tip.textColor=UIColor.black
    
    tip.textAlignment= .center
    
    tip.font=UIFont.systemFont(ofSize:16);
    
    return tip
    
    }()
    
    lazy var codeImageView:UIImageView= {
    
    let imageView =UIImageView(image:UIImage(named:"front"))
    
    imageView.frame=self.tip.frame
    
    returnimageView
    
    }()
    
    override func touchesMoved(_touches:Set, with event:UIEvent?) {
    
    let touchess = touches as NSSet
    
    let touch:UITouch= touchess.anyObject() as! UITouch
    
    let cententPoint = touch.location(in:codeImageView)
    
    let rect =CGRect(x: cententPoint.x, y: cententPoint.y, width:20, height:20)
    
    UIGraphicsBeginImageContextWithOptions(codeImageView.bounds.size,false,0)
    
    let ref =UIGraphicsGetCurrentContext()
    
    codeImageView.layer.render(in: ref!)
    
    ref!.clear(rect)
    
    let image =UIGraphicsGetImageFromCurrentImageContext()
    
    UIGraphicsEndImageContext()
    
    codeImageView.image= image
    
    }
    

    相关文章

      网友评论

          本文标题:iOS刮奖效果

          本文链接:https://www.haomeiwen.com/subject/dymthxtx.html