zoukankan      html  css  js  c++  java
  • Toggle Slow Animations

    Toggle Slow Animations

     

    iOS Simulator has a feature that slows animations, you can toggle it either by pressing ⌘T or choosing Debug > Toggle Slow Animations in Frontmost App. It’s very useful, but what if we want to do the same on device? It’s easy, fast and simple.

    CALayer has a property called speed, which is a time multiplier. This means that if we have an animation with a duration of 1 second, and set the layer’s speed to 2, it’ll take just 0.5 seconds to finish. The best thing about it is that it’s related to the parent layer. So when we change the speed of a particular CALayer, every child layer will be affected. So, if we change UIWindow layer speed, every CALayer in our application will perform animations with that custom speed value. That leaves us with this two extensions:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    
    extension UIWindow {
    
        var slowAnimationsEnabled: Bool {
            get {
                return layer.speed != 1
            }
            set {
                layer.speed = newValue ? 0.2 : 1
            }
        }
    }
    
    extension UIApplication {
    
        func setSlowAnimationsEnabled(enabled: Bool) {
            windows.map({ window in (window as? UIWindow)?.slowAnimationsEnabled = enabled })
        }
    }
    

    And you can call it in both ways:

    1
    2
    
    UIApplication.sharedApplication().keyWindow?.slowAnimationsEnabled = true
    UIApplication.sharedApplication().setSlowAnimationsEnabled(true)
    

    You can go further and expose this to your testers, through iOS Settings Bundle or a fancy shake gesture. Pretty handy!

  • 相关阅读:
    C# HTTP
    Iframe的应用
    亚马逊S3下载上传文件
    ubuntu14.0.4.3 devstack 安装openstack
    转--脉络清晰的BP神经网络讲解,赞
    转载:稀疏矩阵存储格式总结+存储效率对比:COO,CSR,DIA,ELL,HYB
    Python 元组
    pyhon 模块与库
    开源推荐简介
    转载--PayPal高级工程总监:读完这100篇论文 就能成大数据高手
  • 原文地址:https://www.cnblogs.com/ioriwellings/p/6590229.html
Copyright © 2011-2022 走看看