3 回答

TA貢獻1712條經(jīng)驗 獲得超3個贊
使用新的基于塊的UIKit動畫方法可以更加簡單。
假設(shè)以下代碼位于視圖控制器中,并且您要交叉溶解的UIImageView是可通過屬性self.imageView尋址的self.view的子視圖。然后,您需要做的就是:
UIImage * toImage = [UIImage imageNamed:@"myname.png"];
[UIView transitionWithView:self.imageView
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imageView.image = toImage;
} completion:nil];
做完了
并在Swift中進行操作,就像這樣:
let toImage = UIImage(named:"myname.png")
UIView.transitionWithView(self.imageView,
duration:5,
options: UIViewAnimationOptions.TransitionCrossDissolve,
animations: { self.imageView.image = toImage },
completion: nil)
斯威夫特3.0
let toImage = UIImage(named:"myname.png")
UIView.transition(with: self.imageView,
duration: 0.3,
options: .transitionCrossDissolve,
animations: {
self.imageView.image = toImage
},
completion: nil)

TA貢獻1807條經(jīng)驗 獲得超9個贊
是的,您說的是絕對正確的,那就是做到這一點的方法。我編寫了此方法,并始終使用它來淡化我的圖像。我CALayer為此處理。您需要為此導(dǎo)入Core Animation。
+ (void)fadeInLayer:(CALayer *)l
{
CABasicAnimation *fadeInAnimate = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeInAnimate.duration = 0.5;
fadeInAnimate.repeatCount = 1;
fadeInAnimate.autoreverses = NO;
fadeInAnimate.fromValue = [NSNumber numberWithFloat:0.0];
fadeInAnimate.toValue = [NSNumber numberWithFloat:1.0];
fadeInAnimate.removedOnCompletion = YES;
[l addAnimation:fadeInAnimate forKey:@"animateOpacity"];
return;
}
您可以執(zhí)行相反操作以淡出圖像。之后淡出。您只需將其從Superview中刪除(即UIImageView)。[imageView removeFromSuperview]。
- 3 回答
- 0 關(guān)注
- 423 瀏覽
添加回答
舉報