我想動畫一個UIButton向上移動屏幕。在任何時候用戶都可以觸摸它。但是,它在移動時似乎沒有響應觸摸,僅在其動畫的開始和結束時才響應。我想這是因爲按鈕本身不動,只是它的形象。任何想法如何我可以解決這個問題?這是我的代碼到目前爲止。謝謝!動畫移動UIButton沒有響應觸摸/水龍頭移動時
- (void)viewDidLoad {
[self newBubble];
[super viewDidLoad];
}
- (void)newBubble {
UIButton *bubble = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
bubble.frame = CGRectMake(10, 380, 50, 50);
UIImage *bubbleImage = [UIImage imageNamed:@"bubble.png"];
[bubble setBackgroundImage:bubbleImage forState:UIControlStateNormal];
bubble.imageView.contentMode = UIViewContentModeScaleAspectFit;
[bubble addTarget:self action:@selector(bubbleBurst:) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:bubble];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0];
CGAffineTransform newTransform = CGAffineTransformMakeScale(1.5, 1.5);
bubble.transform = CGAffineTransformTranslate(newTransform, 10, -200);
[UIView commitAnimations];
}
- (IBAction)bubbleBurst:(id)sender {
NSLog(@"Bubble burst");
UIButton *bubbleBurst = sender;
[bubbleBurst removeFromSuperview];
}
確實我希望你是對的。任何想法使用哪些類,但?我嘗試了CAKeyframeAnimation,移動圖層的'位置'屬性,但同樣的問題。和CABasicAnimation一樣。我會堅持下去,只是希望有人能夠早點給我指點。也許我應該使用NSTimer更新按鈕的位置?但是,這會得到相當凌亂的多個按鈕... – Smikey 2010-08-24 10:22:02