我想动画一个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