Apple developed iOS add to the shopping cart animation effect

Source: Internet
Author: User
The code is as follows Copy Code
#pragma mark-Shopping Basket button click event
-(void) Shoppingcartbuttonaction: (uibutton*) Sender
{
if ([[Userdef objectforkey:@ "id"]isequaltostring:@ "0"]) {
[Self showhudtextonly:@ "please log in, then do the operation"];
Return
}
Nsdictionary *parameters = @{
@ "user_id": [Userdef objectforkey:@ "id"],
@ "gp_id": [NSString stringwithformat:@ "%@", [cell2array[sender.tag-101] objectforkey:@ "gp_id"]],
@ "Number": @1
};
[Self defaultrequestwithurl:kaddtocarturl withparameters:parameters withmethod:@ "POST" withblock:^ (NSDictionary * Dict, Nserror *error) {
if ([[Dict Objectforkey:kcode] integervalue]==1) {
This part of the animation to Self.view as a reference system for
Uiimageview *imageview=[[uiimageview alloc]initwithimage:[uiimage imagenamed:@ "Button_hot_shopping-cart_red-1"];
Imageview.contentmode=uiviewcontentmodecenter;
Imageview.frame = Sender.bounds;
Imageview.hidden=yes;
Cgpoint point= Sender.frame.origin;
Imageview.center=point;
Calayer *layer=[[calayer Alloc]init];
layer.contents=imageview.layer.contents;
Layer.frame=imageview.frame;
Layer.opacity=1;
[Self.view.layer Addsublayer:layer];
The end of the animation is sel.view as the reference system
Cgpoint endpoint= Cgpointmake (screen_width*7/10.0, screen_height-22);
Uibezierpath *path=[uibezierpath Bezierpath];
Animation starting point
CGRect rect=[sender convertRect:sender.bounds ToView:self.view];
Cgpoint Startpoint=cgpointmake (rect.origin.x +rect.size.width/2, rect.origin.y +RECT.SIZE.HEIGHT/2);
[Path Movetopoint:startpoint];
Middle point of Bezier curve
float Sx=startpoint.x;
float Sy=startpoint.y;
float Ex=endpoint.x;
float Ey=endpoint.y;
Float x=sx+ (EX-SX)/3;
Float y=sy+ (ey-sy) *0.5-400;
Cgpoint Centerpoint=cgpointmake (x,y);
[path Addquadcurvetopoint:endpoint controlpoint:centerpoint];

Cakeyframeanimation *animation=[cakeyframeanimation animationwithkeypath:@ "position"];
Animation.path = path. Cgpath;
Animation.removedoncompletion = NO;
Animation.fillmode = Kcafillmodeforwards;
animation.duration=0.8;
animation.delegate=self;
Animation.autoreverses= NO;
Animation.timingfunction=[camediatimingfunction Functionwithname:kcamediatimingfunctioneasein];
[Layer addanimation:animation forkey:@ "buy"];
Update the corner mark
[Self cornernumber];
}else {
[Self showhudtextonly:[dict objectforkey:kmessage]];
}
}];
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.