2
大家好我是xcode的新手,我嘗試通過更改圖像來觸摸動畫中的氣球:這是我的代碼: 現在我正面臨的問題它是不是動畫圖像意味着動畫計時器不工作:請指導我該怎麼做,以便隨着時間動畫圖像:如果我沒有做好它,請指導我,我怎麼能通過NSTimer做到這一點?如何在一段時間後通過更改圖像來創建動畫
-(void)baloonbursting:(UIButton *)button withEvent:(UIEvent *)event{
if ([[UIImage imageNamed:@"redbaloons.png"] isEqual:button.currentImage]) {
NSLog(@"em redbaloons.png");
UIImage *bubbleImage3 = [UIImage imageNamed:@"redburst.png"];
[button setImage:bubbleImage3 forState:UIControlStateNormal];
}
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView animateWithDuration:1.0f animations:^(){
// define animation
if ([[UIImage imageNamed:@"redburst.png"] isEqual:button.currentImage]) {
NSLog(@"em redbaloons.png");
UIImage *bubbleImage3 = [UIImage imageNamed:@"redburst2.png"];
[button setImage:bubbleImage3 forState:UIControlStateNormal];
}
}
completion:^(BOOL finished){
// after the animation is completed call showAnimation again
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseOut|UIViewAnimationOptionAllowUserInteraction animations:^{
} completion:^(BOOL finished){
if (finished) {
[button removeFromSuperview];
}}];
}];
}
我不認爲UIButton的圖像屬性可以是動畫的。 – Andrew
指導我如何通過NSTIMER做到這一點? – Steve
爲什麼你在if中創建UIImage只是爲了檢查圖像是否相等,難道你不能僅僅使用圖像的'name'屬性? –