手势开端的时刻创建animator。然后暂停,在这里,动画暂停的本质同样是将Layer的speed设置为0。
动画的完成率等同于手势移动的距离除以总距离。
当手势停止的时刻,我们调用了continueAnimation让动画持续履行到停止。其拭魅这种需求比较少见,最常见的应当是当手势停止的时刻让动画逗留在这个阶段而不是持续进行动画。
在这里,我们改革一下这个动画,让它更相符我们的用户习惯。
起首,在手势事宜的外部定义好这个animator。
- circle.backgroundColor = UIColor.red
- circle.layer.cornerRadius = 10
- circle.frame = CGRect.init(x: 10, y: 100, width: 20, height: 20)
- circle.isUserInteractionEnabled = true
- self.view.addSubview(circle)
- animator = UIViewPropertyAnimator.init(duration: 1, curve: .ea搜刮引擎优化ut, animations: {
- self.circle.frame = self.circle.frame.offsetBy(dx: 100, dy: 0)
- })
- animator.pauseAnimation()
然后棘手势的事宜代码如下。
我们先思虑一个问题:iOS11 之前创建哪类动画最麻烦?
- func handlePan(recognizer:UIPanGestureRecognizer) {
- switch recognizer.state {
- case .began:
- progress = animator.fractionComplete
推荐阅读
Python转JavaScript编译器,天了噜!还能转代码,到底怎么做到的
为懂得决这个问题,Transcrpyt支撑别号章一ㄅ念。当在Python中应用<string>.split时,就会被翻译成一个具有Python的split语义的JavaScript函数<string>.py_split。在原生JavaScript代铝闼楝split指代的>>>详细阅读
地址:http://www.17bianji.com/lsqh/38570.html
1/2 1