0

我必须为 UIButtons 数组执行收缩和扩展动画。对于单个 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);}];

我怎样才能为 UIbuttons 数组实现相同的效果。

4

2 回答 2

1

您可以使用类别。声明一个UIButton类别并添加方法来执行动画。

UIButton+Transform.h

@interface UIButton (Transform)

- (void) applyAnimation;

@end

UIButton+变换.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)];

这将调用数组中所有按钮的动画方法。

希望有帮助!

于 2013-07-12T07:20:46.577 回答
-1

在动画块内使用 a for,例如:

[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);}];
    }
}];
于 2013-07-12T07:14:17.483 回答