尝试使用以下方法对imageView进行着色时,我必须使用延迟才能更新UI。我哪里错了?
class func tintImageView(imageView : UIImageView, withColor color:UIColor) {
var coloredImage = imageView.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
imageView.image = coloredImage
imageView.tintColor = color
}
延迟功能:
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
使用示例:
delay(0.011, closure: { () -> () in
tintImageView(button.imageView!, withColor: tintColor)
})
感谢您的帮助!