Basic use of attenuation animations for IOS pop animations

Source: Internet
Author: User

Fade animation

-(void) Viewdidload {

[Super Viewdidload];

[Self initcirclebtn];

}

-(void) Initcirclebtn {

Instantiate the gesture and eventually add the gesture to the circle button

Uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc]initwithtarget:self Action: @selector (Handlepan:)];

Instantiate a circular button

UIButton *circlebtn = [[UIButton alloc]init];

Circlebtn.bounds = CGRectMake (0, 0, 100, 100);

Circlebtn.center = Self.view.center;

Circlebtn.backgroundcolor = [Uicolor Redcolor];

CircleBtn.layer.cornerRadius = Cgrectgetwidth (circlebtn.frame)/2;

[Circlebtn Addgesturerecognizer:pan];

[Circlebtn addtarget:self Action: @selector (Handledown:) Forcontrolevents:uicontroleventtouchdown];

[Self.view ADDSUBVIEW:CIRCLEBTN];

}

-(void) Handlepan: (Uipangesturerecognizer *) Recognizer {

Cgpoint translation = [recognizer TranslationInView:self.view];

Recognizer.view.center = Cgpointmake (recognizer.view.center.x + translation.x, Recognizer.view.center.y + TRANSLATION.Y);

[Recognizer Settranslation:cgpointmake (0, 0) InView:self.view]; //This is important because Handlepan: it will continue to be called, and the button will move very quickly if the displacement generated by the last call to the method is not zeroed .

//When you let go, start the decay animation

if (recognizer.state = = uigesturerecognizerstateended) {

Cgpoint velocity = [recognizer VelocityInView:self.view]; //Get let go when gesture in controller view speed

Popdecayanimation *popanimation = [Popdecayanimation animationwithpropertynamed:kpoplayerposition]; //Instantiate attenuation animation, which acts on position

[Popanimation Setvelocity:[nsvalue valuewithcgpoint:velocity]; //Set the initial speed of the Falloff animation

[Recognizer.view pop_addanimation:popanimation forkey:@ "Suibian"]; //Add falloff Animation to circular button

}

}

Basic use of attenuation animations for IOS pop animations

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.