亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何沿曲線路徑設置視圖或圖像的移動動畫?

如何沿曲線路徑設置視圖或圖像的移動動畫?

忽然笑 2019-08-09 14:28:00
如何沿曲線路徑設置視圖或圖像的移動動畫?我正在開發一個商務應用程序。當我將一個項目添加到購物車時,我想創建一個效果,其中項目的圖像遵循彎曲的路徑,最終在購物車選項卡上。如何沿這樣的曲線創建圖像動畫?
查看完整描述

3 回答

?
互換的青春

TA貢獻1797條經驗 獲得超6個贊

為了擴展Nikolai所說的,處理這個問題的最佳方法是使用Core Animation為Bezier路徑上的圖像或視圖的運動設置動畫。這是使用CAKeyframeAnimation完成的。例如,我使用以下代碼將視圖圖像設置為圖標以指示保存(如此應用程序視頻中所示):

首先導入QuartzCore頭文件 #import <QuartzCore/QuartzCore.h>

UIImageView *imageViewForAnimation = [[UIImageView alloc] initWithImage:imageToAnimate];

imageViewForAnimation.alpha = 1.0f;

CGRect imageFrame = imageViewForAnimation.frame;

//Your image frame.origin from where the animation need to get start

CGPoint viewOrigin = imageViewForAnimation.frame.origin;

viewOrigin.y = viewOrigin.y + imageFrame.size.height / 2.0f;

viewOrigin.x = viewOrigin.x + imageFrame.size.width / 2.0f;


imageViewForAnimation.frame = imageFrame;

imageViewForAnimation.layer.position = viewOrigin;

[self.view addSubview:imageViewForAnimation];


// Set up fade out effect

CABasicAnimation *fadeOutAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];

[fadeOutAnimation setToValue:[NSNumber numberWithFloat:0.3]];

fadeOutAnimation.fillMode = kCAFillModeForwards;

fadeOutAnimation.removedOnCompletion = NO;


// Set up scaling

CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];

[resizeAnimation setToValue:[NSValue valueWithCGSize:CGSizeMake(40.0f, imageFrame.size.height * (40.0f / imageFrame.size.width))]];

resizeAnimation.fillMode = kCAFillModeForwards;

resizeAnimation.removedOnCompletion = NO;


// Set up path movement

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

pathAnimation.calculationMode = kCAAnimationPaced;

pathAnimation.fillMode = kCAFillModeForwards;

pathAnimation.removedOnCompletion = NO;

//Setting Endpoint of the animation

CGPoint endPoint = CGPointMake(480.0f - 30.0f, 40.0f);

//to end animation in last tab use 

//CGPoint endPoint = CGPointMake( 320-40.0f, 480.0f);

CGMutablePathRef curvedPath = CGPathCreateMutable();

CGPathMoveToPoint(curvedPath, NULL, viewOrigin.x, viewOrigin.y);

CGPathAddCurveToPoint(curvedPath, NULL, endPoint.x, viewOrigin.y, endPoint.x, viewOrigin.y, endPoint.x, endPoint.y);

pathAnimation.path = curvedPath;

CGPathRelease(curvedPath);


CAAnimationGroup *group = [CAAnimationGroup animation]; 

group.fillMode = kCAFillModeForwards;

group.removedOnCompletion = NO;

[group setAnimations:[NSArray arrayWithObjects:fadeOutAnimation, pathAnimation, resizeAnimation, nil]];

group.duration = 0.7f;

group.delegate = self;

[group setValue:imageViewForAnimation forKey:@"imageViewBeingAnimated"];


[imageViewForAnimation.layer addAnimation:group forKey:@"savingAnimation"];


[imageViewForAnimation release];


查看完整回答
反對 回復 2019-08-09
  • 3 回答
  • 0 關注
  • 810 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號