![](/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.