iOS rebound animation effect

Source: Internet
Author: User

Create a new item, and then put a view in the storyboard and set the view position in AutoLayout

And the top of the distance (set Y)


Distance from left (set X)

Set size

Drag a port for view

Add a drag gesture to the view in Viewdidload

-(void) viewdidload {
    [super viewdidload];
    Add drag gesture
    uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc] 	initwithtarget:self action: @selector (Handlepan:)];
    [Self.springbackview Addgesturerecognizer:pan];
    Do no additional setup after loading the view, typically from a nib.
}

Next, implement Handlepan:

-(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:cgpointzero InView:self.view];
    
    if (recognizer.state = = uigesturerecognizerstateended) {
    
        [UIView animatewithduration:0.3 delay:0 usingspringwithdamping:0.5 initialspringvelocity:10 options:0 animations:^{
            [Self.springbackview Layoutifneeded];
    } Completion:nil];
        
    }

OK, now run your program to drag the view ...




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.