購物車動畫

2021-06-26 07:04:51 字數 2170 閱讀 2680

//金幣終點的x位置

cgfloat positionx   = 290.0f;    //終點x

//金幣終點的y位置

cgfloat positiony   = 500.0f;    //終點y

cgmutablepathref path = cgpathcreatemutable();

//金幣的起始x位置

int fromx       = 20;//arc4random() % 320;     //起始位置:x軸上隨機生成乙個位置

//金幣的起始y位置

int height      = [uiscreen mainscreen].bounds.size.height + coin.frame.size.height; //y軸以螢幕高度為準

int fromy       = -100;//arc4random() % (int)positiony; //起始位置:生成位於福袋上方的隨機乙個y座標

//金幣橫向拋物線的幅度

cgfloat cpx = 200;//positionx + (fromx - positionx)/2;    //x控制點

//金幣縱向拋物線的幅度

cgfloat cpy = -30;//fromy / 2 - positiony;                //y控制點,確保拋向的最大高度在螢幕內,並且在福袋上方(負數)

//動畫的起始位置

cgpathmovetopoint(path, null, fromx, 20);

cgpathaddquadcurvetopoint(path, null, cpx, cpy, positionx, positiony);

cakeyframeanimation *animation = [cakeyframeanimation animationwithkeypath:@"position"];

[animation setpath:path];

cfrelease(path);

path = nil;

//影象由大到小的變化動畫

cgfloat from3dscale = 1 + arc4random() % 10 *0.1;

cgfloat to3dscale = from3dscale * 0.5;

cakeyframeanimation *scaleanimation = [cakeyframeanimation animationwithkeypath:@"transform"];

scaleanimation.values = @[[nsvalue valuewithcatransform3d:catransform3dmakescale(from3dscale, from3dscale, from3dscale)], [nsvalue valuewithcatransform3d:catransform3dmakescale(to3dscale, to3dscale, to3dscale)]];

scaleanimation.timingfunctions = @[[camediatimingfunction functionwithname:kcamediatimingfunctioneaseout], [camediatimingfunction functionwithname:kcamediatimingfunctioneasein]];

//動畫組合

caanimationgroup *group = [caanimationgroup animation];

group.delegate = self;

group.duration = duration;

group.fillmode = kcafillmodeforwards;

group.removedoncompletion = no;

group.animations = @[scaleanimation, animation];

[coin.layer addanimation:group forkey:@"position and transform"];

}- (void)animationdidstop:(caanimation *)anim finished:(bool)flag}}

}//福袋晃動動畫

- (void)bagshakeanimation

- (void)didreceivememorywarning

@end

新增購物車弧形動畫

問題描述 購物車動畫,就是選擇的時候乙個動畫元素從選擇處以拋物線調入左下角的購物車圖示,進入後購物車有乙個搖晃效果。如下圖 乙個小小的動畫,需求也是定製的,不高新到網上找外掛程式。也不多。找的外掛程式還要改東西,又引入更多 於是決定自己寫。解題思路 相信大家也不願意看大堆的 寫下關鍵點吧。1.準備 ...

購物車(註冊 登入 購物 購物車 結帳)

購物車 註冊 登入 購物 購物車 結帳 shopping car dict dict money 0 def input username pwd username input username pwd input pwd return username,pwd def goods get with...

swift 商品加入購物車動畫

mark 商品拋入購物車的動畫效果 extension qhgoodlistviewcontroller 組動畫 groupanimation 組動畫 幀動畫拋入購物車 並放大 縮小圖層增加點動效 private func groupanimation 動畫結束後做一些操作 override fun...