繁体   English   中英

无法使闭包语法在Swift 4中工作

[英]Cannot get closure syntax to work in swift 4

我已经尝试了所有可能的语法变体,但是完成处理程序总是在动画结束之前激活。 我认为我应该用其他东西代替Bool吗?

UIView.transition(with: swipeForPicturesIndicator,
                              duration: 1,
                              options: .curveEaseIn,
                              animations: {
                                self.swipeForPicturesIndicator.alpha = 0
            },
                              completion: { (Bool) -> Void in
                self.swipeForPicturesIndicator.isHidden = true
                self.swipeForPicturesIndicator.alpha = 0.8
            })

Bool值指示在调用完成块时动画是否结束。 如果该值为false则表示您的动画已中断。

您应该使用animate而不是transition

    UIView.animate(withDuration: 1,
                   delay: 0,
                   options: .curveEaseIn,
                   animations: {
      self.swipeForPicturesIndicator.alpha = 0
    }) { (completed) in

      /* Optionally check if animation finished */

      self.swipeForPicturesIndicator.isHidden = true
      self.swipeForPicturesIndicator.alpha = 0.8
    }

尝试这个

self.swipeForPicturesIndicator.alpha = 0
UIView.transition(with: swipeForPicturesIndicator,
                              duration: 1,
                              options: .curveEaseIn,
                              animations: {

                self.swipeForPicturesIndicator.alpha = 0.8

            },
                              completion: nil)

您可能要使用动画而不是过渡:

UIView.animate(withDuration: 1, delay: 0, options: .curveEaseIn, animations: { 
        self.swipeForPicturesIndicator.alpha = 0
    }) { (success) in
        self.swipeForPicturesIndicator.isHidden = true
        self.swipeForPicturesIndicator.alpha = 0.8
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM