gpt4 book ai didi

ios - UIButton 移动动画

转载 作者:行者123 更新时间:2023-11-28 22:36:57 28 4
gpt4 key购买 nike

我想知道是否可以创建一个 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];
}];

最佳答案

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

UIViewAnimationOptionCurveEaseInOut
UIViewAnimationOptionCurveEaseIn
UIViewAnimationOptionCurveEaseOut
UIViewAnimationOptionCurveLinear

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

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

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

关于ios - UIButton 移动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15663213/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com