我有这段代码可以移动图像,但我想在打开页面后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")
答案 0 :(得分:1)
我不确定你是否在寻找它。除了使用像Rashwan建议的计时器之外,您还可以使用GCD。
在override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
loadImage()
let delayInSeconds = 5.0
let popTime = dispatch_time(DISPATCH_TIME_NOW,
Int64(delayInSeconds * Double(NSEC_PER_SEC)))
dispatch_after(popTime, dispatch_get_main_queue()) {
//You can add some "finish up" operations here
}
}
中显示图片,然后添加以下代码,延迟5秒,如下:
plot(Average.BL~Wet.weight, log="xy")
reg=lm(log(Average.BL)~log(Wet.weight))
abline(reg, untf=FALSE)
答案 1 :(得分:0)
要做任何事情之前要等5秒才能使用Timer
,请参阅下面的使用方法:
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")
}