UIButton运动动画

时间:2013-03-27 15:51:14

标签: ios animation uibutton

我想知道是否可以创建一个UIButton动画来使按钮在屏幕上快速滑动,在到达中心时减慢速度,然后加速并退出另一侧的屏幕。按钮没有被按下,所以我使用:

userInteractionEnabled = NO;

这就是我试图做的事情:

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];
    }];

1 个答案:

答案 0 :(得分:2)

您可以定义动画选项。有趣的选择

UIViewAnimationOptionCurveEaseInOut
UIViewAnimationOptionCurveEaseIn 
UIViewAnimationOptionCurveEaseOut
UIViewAnimationOptionCurveLinear

您需要使用以下UIView的Class方法才能使用这些选项

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

当然,您可以通过在完成块中启动新动画来制作嵌套动画。

相关问题