【发布时间】:2014-11-05 00:32:25
【问题描述】:
谁能告诉我为什么这不起作用?:
//Changing the Images
- (void) squareOneColour {
NSUInteger r = arc4random_uniform(5);
[self.squareOne setBackgroundImage:[self.colorArray objectAtIndex:r] forState:UIControlStateNormal];
}
//Moving buttons
- (void) squareOneMover {
NSUInteger r = arc4random_uniform(3);
[self.squareOne setHidden:NO];
CGPoint originalPosition = self.squareOne.center;
originalPosition.y = -55;
[self.squareOne setCenter:originalPosition];
CGPoint position = self.squareOne.center;
position.y += 760;
[UIView animateWithDuration:r + 3
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
[self.squareOne setCenter:position];
}
completion:^(BOOL complete) {
if (complete) {
[self squareOneColour];
[self squareOneMover];
}
}
];
}
我正在尝试让UIButton 在屏幕上设置动画,并在动画完成后重复播放,但背景不同。上面的代码似乎应该可以工作,但第二个动画从未完成。 (UIButton 动画一次,然后一切都停止)。我尝试将下面显示的代码(放入完成块中),使用外部 NSUInteger 方法为 r 创建一个随机数,但它永远不会工作。但是当我将 r 替换为不同的数字(如 1 或 2)时,它确实有效。
【问题讨论】:
标签: objective-c animation uibutton