Swift: 如何触发Xcode个项目中的函数?
Swift: How to trigger functions in Xcode projects?
我是一个编程新手,我不知道如何在我的项目中触发我的功能。我只需要我的功能 运行 4 秒,然后它就不必再工作了。我不想要一个按钮来调用该功能,我希望它是自动的!谢谢!
PS。定时器变量就是上面的一个定时器运行ning.
func fadeLabels() {
if timerCount > 3 {
timer.invalidate()
timerRunning = false
}
//Label Fade Functionality
if timerCount == 1 {
UIView.animateWithDuration(1.0, animations: { () -> Void in
self.countdownThree.alpha = 0
})
}
if timerCount == 2 {
UIView.animateWithDuration(1.0, animations: { () -> Void in
self.countdownTwo.alpha = 0
})
}
if timerCount == 3 {
UIView.animateWithDuration(1.0, animations: { () -> Void in
self.countdownOne.alpha = 0
})
}
}
感谢所有帮助我解决愚蠢问题的人!
在控制器的viewDidLoad方法中添加代码:
NSTimer.scheduledTimerWithTimeInterval(4, target: self, selector: "fadeLabels", userInfo: nil, repeats: false)
我是一个编程新手,我不知道如何在我的项目中触发我的功能。我只需要我的功能 运行 4 秒,然后它就不必再工作了。我不想要一个按钮来调用该功能,我希望它是自动的!谢谢!
PS。定时器变量就是上面的一个定时器运行ning.
func fadeLabels() {
if timerCount > 3 {
timer.invalidate()
timerRunning = false
}
//Label Fade Functionality
if timerCount == 1 {
UIView.animateWithDuration(1.0, animations: { () -> Void in
self.countdownThree.alpha = 0
})
}
if timerCount == 2 {
UIView.animateWithDuration(1.0, animations: { () -> Void in
self.countdownTwo.alpha = 0
})
}
if timerCount == 3 {
UIView.animateWithDuration(1.0, animations: { () -> Void in
self.countdownOne.alpha = 0
})
}
}
感谢所有帮助我解决愚蠢问题的人!
在控制器的viewDidLoad方法中添加代码:
NSTimer.scheduledTimerWithTimeInterval(4, target: self, selector: "fadeLabels", userInfo: nil, repeats: false)