Alessandro
Alessandro

Reputation: 4100

UIButton movement animtion

I was wondering if it was possible to create a UIButton animation to make the button slide in the screen fast, slow down as it reaches the center, and then speed up and exit the screen on the other side. the button has not to be pressed, so I use:

userInteractionEnabled = NO;

This is what I have tried to do:

UIButton* buttonNumberCountTutorial = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[buttonNumberCountTutorial setTitle:@"2" forState:UIControlStateNormal];
[buttonNumberCountTutorial setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[buttonNumberCountTutorial.titleLabel setFont:[UIFont fontWithName:@"Zapfino" size:40]];
buttonNumberCountTutorial.frame = CGRectMake(-400, 430, 400, 400);
[buttonNumberCountTutorial setBackgroundImage:[UIImage imageNamed:@"socialize-navbar-bg.png"]forState:UIControlStateNormal];
[baseView addSubview:buttonNumberCountTutorial];
[UIView animateWithDuration:1.9f
                 animations:^{

        buttonNumberCountTutorial.frame = CGRectMake(20, 430, 200, 200);

        }
              completion:^(BOOL finished){

                  [buttonNumberCountTutorial removeFromSuperview];
    }];

Upvotes: 0

Views: 79

Answers (1)

Mert
Mert

Reputation: 6065

You can define animation options. The interesting options for you

UIViewAnimationOptionCurveEaseInOut
UIViewAnimationOptionCurveEaseIn 
UIViewAnimationOptionCurveEaseOut
UIViewAnimationOptionCurveLinear

You need to use following Class method of UIView to be able to use these options

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

And of course you can make nested animations by starting a new animation in completion block.

Upvotes: 2

Related Questions