![](/img/trans.png)
[英]UIView animateWithDuration doesn't animate cornerRadius variation
[英]UIView animateWithDuration doesn't animate, it just loads
我正在從網上加載圖片搜索結果,但它們似乎沒有正確設置動畫效果。 為此,我只需要在UIView.animateWithDuration(1.0){}
調用UIView.animateWithDuration(1.0){}
的圖像從nil更改為海報。 但是,它沒有進行動畫處理,而是立即彈出。
這是代碼:
//Poster
//Set the poster first as blank
cell.poster.image = nil
//If I'm provided with a poster path, load an image.
if let imagePath = matchingItems[indexPath.row]["poster_path"] as? String {
//Sessions and Stuff for request
let url = NSURL(string: "http://i.imgur.com/b3DKTX2.png")
let urlRequest = NSURLRequest(URL: url!)
let session = NSURLSession.sharedSession()
//Asynchronous Request:
let dataTask = session.dataTaskWithRequest(urlRequest, completionHandler: { (data, response, error) -> Void in
if let poster = UIImage(data: data!) {
dispatch_async(dispatch_get_main_queue()) {
//Animate the poster in
UIView.animateWithDuration(1.0) {
cell.poster.image = poster
}
}
}
})
dataTask.resume()
} else {
//Just use placeholder if no image exists
cell.poster.image = UIImage(named: "Placeholder.jpg")
}
您不能為UIImageView
的image
屬性設置動畫。 由於您希望圖像淡入,因此可以設置其alpha
屬性的動畫。
像這樣:
cell.poster.alpha = 0.0 // hide it
cell.poster.image = poster // set it
UIView.animateWithDuration(1.0) {
cell.poster.alpha = 1.0 // fade it in
}
許多屬性可以設置動畫,但不能設置UIImageView
的image
屬性。動畫屬性的更多信息: https : //developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/AnimatableProperties/AnimatableProperties.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.