繁体   English   中英

另一个 func 中的 Swift 函数 func 不能工作两次

[英]Swift function func in another func doesn't work twice

有一段 Swift 代码

import UIKit class ViewController: UIViewController {

@IBOutlet weak var sphere: UIImageView!
@IBAction func startButton(_ sender: UIButton) {
        }


override func viewDidLoad() {
    super.viewDidLoad()
}

@IBAction func stepUpDown(_ sender: UIStepper) {
    let t = Double(sender.value)
    animateSphere(timOfDel: t, xTransaktion: 120)
    //animateSphere(timOfDel: t, xTransaktion: -120) //**QUESTION ABOUT THIS**
    print("time duration \(t)")
}


private func animateSphere(timOfDel: Double, xTransaktion: Double) {
    let options: UIView.AnimationOptions = [.curveEaseInOut]

   
    UIView.animate(withDuration: timOfDel,
                   delay: 0,
                   options: options,
                   animations: { [weak self] in
                    self?.sphere.transform = CGAffineTransform(translationX: CGFloat(xTransaktion), y: 0)
                    
    }, completion: nil)
} }

问题是:为什么当我取消注释 func animateSphere()模拟器时会显示函数的最后一个、第二个状态?

好的,最后一种方法有效,但更好地用于简单动画 .center 方法,例如 self?.sphere.center = CGPoint(x: gotoX, y: gotoY)

暂无
暂无

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

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