<i id='5ZqNR'><tr id='5ZqNR'><dt id='5ZqNR'><q id='5ZqNR'><span id='5ZqNR'><b id='5ZqNR'><form id='5ZqNR'><ins id='5ZqNR'></ins><ul id='5ZqNR'></ul><sub id='5ZqNR'></sub></form><legend id='5ZqNR'></legend><bdo id='5ZqNR'><pre id='5ZqNR'><center id='5ZqNR'></center></pre></bdo></b><th id='5ZqNR'></th></span></q></dt></tr></i><div id='5ZqNR'><tfoot id='5ZqNR'></tfoot><dl id='5ZqNR'><fieldset id='5ZqNR'></fieldset></dl></div>
    • <bdo id='5ZqNR'></bdo><ul id='5ZqNR'></ul>

  • <legend id='5ZqNR'><style id='5ZqNR'><dir id='5ZqNR'><q id='5ZqNR'></q></dir></style></legend>

      1. <tfoot id='5ZqNR'></tfoot>
      2. <small id='5ZqNR'></small><noframes id='5ZqNR'>

        如何使用 Swift 3 为按钮制作摇动动画

        时间:2023-07-07
        <tfoot id='i1QGq'></tfoot>
          <bdo id='i1QGq'></bdo><ul id='i1QGq'></ul>

            <tbody id='i1QGq'></tbody>
            <legend id='i1QGq'><style id='i1QGq'><dir id='i1QGq'><q id='i1QGq'></q></dir></style></legend>

              • <small id='i1QGq'></small><noframes id='i1QGq'>

                <i id='i1QGq'><tr id='i1QGq'><dt id='i1QGq'><q id='i1QGq'><span id='i1QGq'><b id='i1QGq'><form id='i1QGq'><ins id='i1QGq'></ins><ul id='i1QGq'></ul><sub id='i1QGq'></sub></form><legend id='i1QGq'></legend><bdo id='i1QGq'><pre id='i1QGq'><center id='i1QGq'></center></pre></bdo></b><th id='i1QGq'></th></span></q></dt></tr></i><div id='i1QGq'><tfoot id='i1QGq'></tfoot><dl id='i1QGq'><fieldset id='i1QGq'></fieldset></dl></div>

                1. 本文介绍了如何使用 Swift 3 为按钮制作摇动动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个每 3 秒调用一次的函数.如何为左右晃动的按钮制作晃动动画.

                  I have a function that gets called every 3 seconds. How can I make a shaking animation for the button that shakes side to side.

                  func shakeButton() {
                      if opened == false {
                          //Shake Animation
                      }
                  }
                  

                  推荐答案

                  如果我理解正确,请在摇动动画上试试这个.只需在您的 UIButton 子类中使用此方法

                  if I understood you correctly, try this on shake animation. Simply use this method in your UIButton subclass

                  class CustomButton: UIButton {
                  
                      func shake() {
                          let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
                          animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
                          animation.duration = 0.6
                          animation.values = [-20.0, 20.0, -20.0, 20.0, -10.0, 10.0, -5.0, 5.0, 0.0 ]
                          layer.add(animation, forKey: "shake")
                      }
                  }
                  

                  然后您在代码或故事板/xib 中的某处创建 CustomButton 并调用 myButton.shake()

                  Then you create CustomButton somewhere in code or storyboard/xib and call myButton.shake()

                  您可以根据需要简单地采用此解决方案

                  You can simply adopt this solution on your needs

                  UPD:我有编辑示例而不是完全符合您的需求

                  UPD: I have edit example than exactly fitted your needs

                  UPD2:另一种解决方案只需创建 UIButton 扩展

                  UPD2: another one solution Just create UIButton extension

                  extension UIButton {
                  
                      func shake() {
                          let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
                          animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
                          animation.duration = 0.6
                          animation.values = [-20.0, 20.0, -20.0, 20.0, -10.0, 10.0, -5.0, 5.0, 0.0 ]
                          layer.add(animation, forKey: "shake")
                      }
                  
                  }
                  

                  ans 使用你的按钮操作回调:

                  ans use on you button action callback:

                  @IBAction func shake(_ sender: UIButton) {
                      sender.shake()
                  }
                  

                  这篇关于如何使用 Swift 3 为按钮制作摇动动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:选定的 UIButton 在选定的 UITableViewCell 内消失 下一篇:Button离开高亮状态时调用方法

                  相关文章

                  • <bdo id='EUeOm'></bdo><ul id='EUeOm'></ul>
                2. <i id='EUeOm'><tr id='EUeOm'><dt id='EUeOm'><q id='EUeOm'><span id='EUeOm'><b id='EUeOm'><form id='EUeOm'><ins id='EUeOm'></ins><ul id='EUeOm'></ul><sub id='EUeOm'></sub></form><legend id='EUeOm'></legend><bdo id='EUeOm'><pre id='EUeOm'><center id='EUeOm'></center></pre></bdo></b><th id='EUeOm'></th></span></q></dt></tr></i><div id='EUeOm'><tfoot id='EUeOm'></tfoot><dl id='EUeOm'><fieldset id='EUeOm'></fieldset></dl></div>

                3. <small id='EUeOm'></small><noframes id='EUeOm'>

                      <tfoot id='EUeOm'></tfoot><legend id='EUeOm'><style id='EUeOm'><dir id='EUeOm'><q id='EUeOm'></q></dir></style></legend>