Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何为UIButton数组设置动画(收缩和展开)_Ios - Fatal编程技术网

Ios 如何为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数组执行收缩和展开动画。对于单按钮,我是这样做的

 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循环时,是否看到问题?