zoukankan      html  css  js  c++  java
  • iOS 停止UIView的block动画

    iOS停止UIView的block动画的方法

    动画执行如下:

    UIView.animateWithDuration(animationDuringTime, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: { [weak self]() -> Void in
                        // do animation
                        animateView?.contentOffset.y = 0
                    }, completion: { [weak self](finished: Bool) -> Void in
                            NSLog("completion")
                    })                    
    

      

    如果在动画过程中突然想停止动画,需要执行如下方法

    // 这里的 animateView 要为 UIView block animation中进行动画效果的view
    animateView.layer.removeAllAnimations()
    

      

    方法执行之后,会UIView block动画会立刻进入completion流程,传入的 finished 值为 false, 可以在代码中通过判断 finished 为 true 或者 false 来区分动画是正常完成还是被停止的。

    UIView.animateWithDuration(animationDuringTime, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: { [weak self]() -> Void in
                        // do animation
                        animateView?.contentOffset.y = 0
                    }, completion: { [weak self](finished: Bool) -> Void in
                            if !finished{
                                NSLog("animation stop")
                            }else{
                                NSLog("completion")
                            }    
                    })   
    

      

      

      

  • 相关阅读:
    前端必备书籍
    搜索引擎的使用技巧
    PS切图
    css背景透明
    前端
    连接查询,A连B,B筛选出多条记录时,选用第一条记录
    mssql 过滤重复记录,取第一笔记录
    MongoDB 日常操作
    OEE计算
    Aspose.Cells: excel 转 pdf
  • 原文地址:https://www.cnblogs.com/FranZhou/p/5128053.html
Copyright © 2011-2022 走看看