2

我有两个 UIButton 让我们说:

UIButton *product UIButton *nextProduct

我正在针对产品在每个按钮上设置图像。

我想以这样的方式为按钮设置动画,即一个按钮淡入,而第二个按钮淡出。

请帮帮我

4

2 回答 2

1

我会改用新的块 API。我不知道第一个答案是否会让用户在动画期间与控件进行交互。我有一个类似的案例并使用了下面的代码。关键是选项:UIViewAnimationOptionAllowUserInteraction

[UIView animateWithDuration:0.5f 
                      delay:0.0f
                    options:UIViewAnimationOptionAllowUserInteraction 
                 animations:^(void) {
    [product setAlpha:0.0f];
    [nextProduct setAlpha:1.0f];

} completion:^(BOOL finished) {
    //Maybe set the new alpha here when the first animation is done?
}];
于 2012-05-15T12:26:12.680 回答
0

将您想要动画的更改包裹在UIView beginAnimations和之间UIView commitAnimations

[UIView beginAnimations:nil context:nil];

product.alpha = 0;
nextProduct.alpha = 1;

[UIView commitAnimations];

查看 UIView 文档以了解如何自定义时间和外观。

于 2012-05-15T12:16:30.110 回答