[英]UIView.transitionWithView not animating
我正在嘗試使用transitionWithVIew
為UIImageView中的圖像變化設置動畫。 圖像改變了,但是似乎沒有動畫。 不知道為什么會這樣。
這是我的代碼:
func changeBackgroundAtIndex(index : Int) {
switch index {
case 0:
animateChangeWithImage(MLStyleKit.imageOfAboutMe)
case 1:
animateChangeWithImage(MLStyleKit.imageOfProjects)
case 2:
animateChangeWithImage(MLStyleKit.imageOfSkills)
case 3:
animateChangeWithImage(MLStyleKit.imageOfEducation)
case 4:
animateChangeWithImage(MLStyleKit.imageOfTheFuture)
default:
animateChangeWithImage(MLStyleKit.imageOfAboutMe)
}
}
func animateChangeWithImage(image : UIImage) {
UIView.transitionWithView(backgroundImageView, duration: 0.4, options: UIViewAnimationOptions.TransitionCrossDissolve, animations: { () -> Void in
self.backgroundImageView.image = image
}, completion: nil)
}
有任何想法嗎? 謝謝 :)
將函數簽名更改為此,同時獲取要更改的圖像和UIImageView本身。 func animateChangeWithImage(image: UIImage, inImageView: UIImageView)
問題出在index
。 我正在獲得index
因為用法是在滾動視圖中滾動,這將不斷更新index
變量,而沒有給它足夠的時間進行動畫。
將changeBackgroundAtIndex
放置在scrollViewDidEndDecelerating
而不是用scrollViewDidScroll
修復。
鑒於實際的圖像本身不是UIView,因此更改時可能沒有對動畫本身進行動畫處理。
這似乎可以滿足您的要求: 如何為UIImageView中的圖像變化設置動畫?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.