gpt4 book ai didi

ios - 点击 iOS 7 时更改背景图像并为 UIButton 设置动画

转载 作者:可可西里 更新时间:2023-11-01 03:34:31 26 4
gpt4 key购买 nike

<分区>

我有一个由以下代码创建的 UIButton

    button =  [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"refresh_icon.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"reload_selected.png"] forState:UIControlStateSelected];
[button addTarget:self action:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 20 , 20)];

在这里,当它被点击时,选择器 buttonAction 被调用,我通过这样的 360 度旋转动画按钮

- (void) buttonAction : (id) sender {
NSLog(@"Reload Button Clicked");
[self runSpinAnimationOnView:self.button duration:1.0 rotations:1.0 repeat:0];

}

- (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat;
{
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
rotationAnimation.duration = duration;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = repeat;

[view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}

它运行良好,但并不是我真正想要的。我想要那个,当我的按钮被点击时,按钮将把图像“reload_selected.png”(我为 UIControlStateSelected 设置)作为背景,然后运行动画。动画结束后,按钮必须再次返回到它的实际背景(“refresh_icon.png”)。

任何人都可以建议对代码进行一些更改以帮助我实现上述操作吗?预先感谢您的帮助。

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