动画移动UIButton在移动时没有响应触摸/轻击

Smi*_*key 2 iphone animation objective-c 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];
}
Run Code Online (Sandbox Code Playgroud)

lem*_*nar 14

+[UIView animateWithDuration:delay:options:animations:completion:]方法需要一个UIViewAnimationOptions参数.如果包含UIViewAnimationOptionAllowUserInteraction,您应该能够在动画时按下按钮:

    [UIView animateWithDuration:5.0
                      delay:0.0
                    options:UIViewAnimationOptionAllowUserInteraction
                 animations:^{
        CGAffineTransform newTransform = CGAffineTransformMakeScale(1.5, 1.5);
        bubble.transform = CGAffineTransformTranslate(newTransform, 10, -200);
    } completion:nil];
Run Code Online (Sandbox Code Playgroud)