所以,我在按钮和动画方面遇到了问题。基本上,我正在使用UIView动画来动画化一个视图,同时还尝试监听视图内的按钮点击。该视图与按钮一样大,实际上是UIImageView的子类,并带有按钮下方的图像。该视图是放置在用户交互启用和裁剪启用的容器视图中的子视图。所有动画和按钮处理都在此UIImageView子类中完成,而
如果我不进行动画,
UIImageView子类init(我将按钮填充为颜色,以便可以看到框架是否正确设置):
startFloating
消息根据需要从单独的类发送。如果我不进行动画,
buttonTapped:
消息会被正确发送,但在动画期间不会发送。我还尝试实现touchesEnded
方法,但行为相同。UIImageView子类init(我将按钮填充为颜色,以便可以看到框架是否正确设置):
- (id)initWithImage:(UIImage *)image {
self = [super initWithImage:image];
if (self != nil) {
// ...stuffs
UIButton *tapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
tapBtn.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
[tapBtn addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
tapBtn.backgroundColor = [UIColor cyanColor];
[self addSubview:tapBtn];
self.userInteractionEnabled = YES;
}
return self;
}
动画方法,用于启动动画(如果我不调用此方法,按钮将正常工作):
- (void)startFloating {
[UIView beginAnimations:@"floating" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:10.0f];
self.frame = CGRectMake(self.frame.origin.x, -self.frame.size.height, self.frame.size.width, self.frame.size.height);
[UIView commitAnimations];
}
因此,要明确:
- 使用UIView动画有效地禁用了按钮。
- 禁用动画会使按钮正常工作。
- 按钮在屏幕上的大小和位置正确,并且可以正确地随着视图移动。
UIViewAnimationOptionAllowUserInteraction
是我所需的。谢谢! - buildsucceeded