作家
登录

终于iOS11里,我们拥有了傻瓜化的交互式动画

作者: 来源: 2017-11-07 15:49:17 阅读 我要评论

  •         case .began: 
  •             animator = UIViewPropertyAnimator.init(duration: 1, curve: .ea搜刮引擎优化ut, animations: { 
  •                 self.circle.frame = self.circle.frame.offsetBy(dx: 100, dy: 0) 
  •             }) 
  •             animator.pauseAnimation() 
  •         case .changed: 
  •             let translation = recognizer.translation(in: self.circle) 
  •             animator.fractionComplete = translation.x/100 
  •              
  •         case .ended: 
  •             animator.continueAnimation(withTimingParameters: nil, durationFactor: 0) 
  •              
  •         default
  •             break 
  •         } 
  •     }   
  • 手势开端的时刻创建animator。然后暂停,在这里,动画暂停的本质同样是将Layer的speed设置为0。

    动画的完成率等同于手势移动的距离除以总距离。

    当手势停止的时刻,我们调用了continueAnimation让动画持续履行到停止。其拭魅这种需求比较少见,最常见的应当是当手势停止的时刻让动画逗留在这个阶段而不是持续进行动画。

    在这里,我们改革一下这个动画,让它更相符我们的用户习惯。

    起首,在手势事宜的外部定义好这个animator。

    1. circle.backgroundColor = UIColor.red 
    2.        circle.layer.cornerRadius = 10 
    3.        circle.frame = CGRect.init(x: 10, y: 100, width: 20, height: 20) 
    4.        circle.isUserInteractionEnabled = true 
    5.        self.view.addSubview(circle) 
    6.         
    7.        animator = UIViewPropertyAnimator.init(duration: 1, curve: .ea搜刮引擎优化ut, animations: { 
    8.            self.circle.frame = self.circle.frame.offsetBy(dx: 100, dy: 0) 
    9.        }) 
    10.        animator.pauseAnimation() 

    然后棘手势的事宜代码如下。

    我们先思虑一个问题:iOS11 之前创建哪类动画最麻烦?

    1. func handlePan(recognizer:UIPanGestureRecognizer) { 
    2.         switch recognizer.state { 
    3.         case .began: 
    4.             progress = animator.fractionComplete 
    5.  
    6.         

        推荐阅读

        Python转JavaScript编译器,天了噜!还能转代码,到底怎么做到的

      为懂得决这个问题,Transcrpyt支撑别号章一ㄅ念。当在Python中应用<string>.split时,就会被翻译成一个具有Python的split语义的JavaScript函数<string>.py_split。在原生JavaScript代铝闼楝split指代的>>>详细阅读


      本文标题:终于iOS11里,我们拥有了傻瓜化的交互式动画

      地址:http://www.17bianji.com/lsqh/38570.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)