所以我有一个按钮和动画的问题。基本上,我使用UIView动画制作视图的动画,同时还试图在视图内按钮上轻敲一下。该视图与按钮一样大,视图实际上是UIImageView的一个子类,在按钮下面有一个图像。该视图是放置在Interface Builder中的容器视图的子视图,启用了用户交互并启用了裁剪。所有动画和按钮处理都在此UIImageView子类中完成,而startFloating
消息根据需要从单独的类发送。iPhone UIView动画禁用UIButton子视图
如果我没有动画,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动画有效地禁用按钮。
- 禁用动画会使按钮生效。
- 按钮的大小和位置正确,并且正确地与视图一起移动。
嗯。这看起来相当不错,但与动画的预期相反。当你说“自己制作动画”时,你指的是NSTimer风格的动画?另外我假设实施触摸方法家族会表现出相同的行为? – bensnider 2010-06-03 20:22:11
所以是使用NSTimer动画我能够以这种方式使用按钮。谢谢。 – bensnider 2010-06-04 14:03:21
你也可以自己做触摸追踪,而不是依赖按钮。它仍然需要一些手动动画,但可能会为您提供更好的交互效果。 – axiixc 2011-06-14 19:01:11