动画移动的UIButton移动时没有响应触摸/水龙头 [英] Animated moving UIButton not responding to touches/taps while moving
问题描述
我想动画一个UIButton拉升屏幕。在任何时候,用户可以触摸它。然而,似乎不移动时,仅在其动画的开始和结束以响应触摸。我想这是因为按钮本身是不动的,只是它的形象。任何想法我怎么能解决这个问题?这里是我的code为止。谢谢!
- (无效)viewDidLoad中{
[个体经营newBubble]
[超级viewDidLoad中];
} - (无效){newBubble
* UIButton的泡沫= [[UIButton的buttonWithType:UIButtonTypeCustom]保留]
bubble.frame = CGRectMake(10,380,50,50);
*的UIImage = bubbleImage [UIImage的imageNamed:@bubble.png];
[泡泡了setBackgroundImage:bubbleImage forState:UIControlStateNormal];
bubble.imageView.contentMode = UIViewContentModeScaleAspectFit;
[泡泡addTarget:自我行动:@选择(bubbleBurst :) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:泡]; [UIView的beginAnimations:无背景:无];
[UIView的setAnimationDuration:5.0];
CGAffineTransform newTransform = CGAffineTransformMakeScale(1.5,1.5);
bubble.transform = CGAffineTransformTranslate(newTransform,10,-200);
[UIView的commitAnimations];
} - (IBAction为)bubbleBurst:(ID)发送{
的NSLog(@泡沫破灭);
*的UIButton = bubbleBurst发送;
[bubbleBurst removeFromSuperview]
}
发布一个类似的问题后,好了,我找到了<一个href=\"http://stackoverflow.com/questions/3568868/is-it-possible-to-successful-animate-a-moving-uibutton\">answer这里
基本上,你必须使用一个框架的NSTimer移动按钮框。在我来说,我很担心会有参与活动的每个按钮太多NSTimers,但最终我用一个定时器,循环通过按钮阵列和移动他们都一个接一个。
I'm trying to animate a UIButton to move up the screen. At any point the user can touch it. However, it doesn't seem to respond to touches while moving, only at the start and end of its animation. I guess this is because the button itself isn't moving, just the image of it. Any ideas how I can solve this? Here's my code so far. Thanks!
- (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];
}
Well after posting a similar question, I found the answer here
Basically, you have to move the button frame by frame using an NSTimer. In my case I was worried there would be too many NSTimers involved moving each button, but in the end I used a single timer which loops through an array of buttons and moves them all one by one.
这篇关于动画移动的UIButton移动时没有响应触摸/水龙头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!