Ios 如何为UIButton数组设置动画(收缩和展开)
我必须为UIButton数组执行收缩和展开动画。对于单按钮,我是这样做的Ios 如何为UIButton数组设置动画(收缩和展开),ios,Ios,我必须为UIButton数组执行收缩和展开动画。对于单按钮,我是这样做的 UIButton *button = [self.destinationButtonsArray objectAtIndex:0]; [UIView beginAnimations:@"shrink" context:(__bridge void *)(button)]; [UIView animateWithDuration:0.7f delay:0 options:UIViewAnimationOption
UIButton *button = [self.destinationButtonsArray objectAtIndex:0];
[UIView beginAnimations:@"shrink" context:(__bridge void *)(button)];
[UIView animateWithDuration:0.7f delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction animations:^{
[UIView setAnimationRepeatCount:3];
CGAffineTransform t = CGAffineTransformMakeScale(1.2f, 1.2f);
button.transform = t;
} completion:^(BOOL finished) {
button.transform = CGAffineTransformMakeScale(1.0f, 1.0f);}];
如何为UIBUTON数组实现相同的效果。在动画块内为使用
,类似于:
[UIView beginAnimations:@"shrink" context:(__bridge void *)(button)];
[UIView animateWithDuration:0.7f delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction animations:^{
[UIView setAnimationRepeatCount:3];
CGAffineTransform t = CGAffineTransformMakeScale(1.2f, 1.2f);
for (UIButton button in self.destinationButtonsArray) {
button.transform = t;
}
} completion:^(BOOL finished) {
for (UIButton button in self.destinationButtonsArray) {
button.transform = CGAffineTransformMakeScale(1.0f, 1.0f);}];
}
}];
你可以使用category。声明ui按钮
类别并添加方法以执行动画
ui按钮+转换.h
@interface UIButton (Transform)
- (void) applyAnimation;
@end
ui按钮+转换.m
@implementation UIButton (Transform)
- (void) applyAnimation {
[UIView beginAnimations:@"shrink" context:self];
[UIView animateWithDuration:0.7f
delay:0
options:UIViewAnimationOptionAutoreverse
| UIViewAnimationCurveEaseInOut
| UIViewAnimationOptionRepeat
| UIViewAnimationOptionAllowUserInteraction
animations:^{
[UIView setAnimationRepeatCount:3];
CGAffineTransform t = CGAffineTransformMakeScale(1.2f, 1.2f);
self.transform = t;
}
completion:^(BOOL finished) {
self.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
}
];
}
@end
对数组调用方法,如下所示
[self.destinationButtonsArray makeObjectsPerformSelector:@selector(applyAnimation)];
这将调用数组中所有按钮的动画方法
希望有帮助 当您将代码放入for循环时,是否看到问题?