//
// ViewController.swift
// Demo
//
// Created by on 2020/10/14.
//
import UIKit
class ViewController: UIViewController,CAAnimationDelegate {
let layer = CAShapeLayer()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.white
self.view.addSubview(backImage)
self.view.addSubview(iconImageView)
self.animationWithView(view: iconImageView)
// self.iconImageView.layer.mask = maskLayer
}
func animationWithView(view :UIImageView){
let margin = 20;
let radius = 25;
let viewWidth = UIScreen.main.bounds.size.width
let viewheight = UIScreen.main.bounds.size.height
let endRadius = sqrt(viewheight*viewheight + viewWidth*viewWidth)
let startRact = CGRect(x: Int(viewWidth) - margin - 2*radius, y: margin, width: 2*radius, height: 2*radius)
let startPath = UIBezierPath(ovalIn: startRact)
let endPath = UIBezierPath(ovalIn: CGRect.insetBy(startRact)(dx: -endRadius, dy: -endRadius))
layer.fillColor = UIColor.red.cgColor
layer.path = startPath.cgPath
view.layer.mask = layer;
let animation = CABasicAnimation(keyPath: "path")
animation.fromValue = startPath.cgPath
animation.toValue = endPath.cgPath
animation.fillMode = CAMediaTimingFillMode.forwards
animation.duration = 2
animation.isRemovedOnCompletion = false
animation.delegate = self
layer.add(animation, forKey: "path")
}
func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
// layer.removeAnimation(forKey: "path")
}
lazy var backImage : UIImageView = {
let image = UIImageView(frame: self.view.bounds)
image.image = UIImage(named: "adlogoOne.png")
image.contentMode = UIView.ContentMode.scaleAspectFill
return image
}()
lazy var iconImageView : UIImageView = {
let image = UIImageView(frame: self.view.bounds)
image.image = UIImage(named: "adlogoTwo.png")
image.contentMode = UIView.ContentMode.scaleAspectFill
image.backgroundColor = UIColor.red
let pan = UITapGestureRecognizer(target: self, action: #selector(panAction(pan:)))
image.addGestureRecognizer(pan)
image.isUserInteractionEnabled = true
return image
}()
@objc func panAction(pan:UITapGestureRecognizer){
let point = pan.location(in: self.iconImageView)
self.maskLayer.frame = CGRect(x: 0, y: 0, width: self.view.bounds.height, height: self.view.bounds.height)
print(point)
}
lazy var maskLayer:CALayer = {
let maskLayer = CALayer.init()
maskLayer.frame = CGRect(x: 10, y: 20, width: 100, height: 100)
maskLayer.cornerRadius = 50;
maskLayer.backgroundColor = UIColor.red.cgColor
return maskLayer
}()
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交