我有一段代码可以使图像移动,但我希望在打开页面5秒后显示此代码。
我该怎么做?谢谢

@IBOutlet weak var moveobj: UIImageView!



override func viewDidAppear(animated: Bool) {


    super.viewDidAppear(animated)


    let orbit = CAKeyframeAnimation(keyPath: "position")
    var affineTransform = CGAffineTransformMakeRotation(0.0)
    affineTransform = CGAffineTransformRotate(affineTransform, CGFloat(M_PI))
    let circlePath = UIBezierPath(arcCenter: CGPoint(x: 198 - (100/2),y: 135 - (100/2)), radius:  CGFloat(155), startAngle: CGFloat(255), endAngle:CGFloat(M_PI * 2 ), clockwise: true)


    orbit.path = circlePath.CGPath
    orbit.duration = 18
    orbit.additive = true
    orbit.repeatCount = 0.15
    orbit.calculationMode = kCAAnimationPaced


    moveobj.layer .addAnimation(orbit, forKey: "orbit")

最佳答案

要在执行任何可以使用Timer的操作之前等待5秒,请参见下面的使用方法:

override func viewDidLoad() {
    super.viewDidLoad()

    // start a new timer with an interval of 5 seconds
    Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(ViewController.showImage), userInfo: nil, repeats: false)
}

// after 5 seconds this class will be called and here you can do your work
func showImage(){
    print("Showing")
}

关于swift - 显示和移动图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39645368/

10-09 01:39