iPhone UIView动画禁用UIButton子视图 [英] iPhone UIView Animation Disables UIButton Subview

查看:130
本文介绍了iPhone UIView动画禁用UIButton子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有按钮和动画的问题。基本上,我使用UIView动画动画的视图,同时也试图监听在视图中的按钮上的水龙头。视图和按钮一样大,视图实际上是UIImageView的子类,按钮下面有一个图像。视图是放置在Interface Builder中的容器视图的子视图,启用了用户交互并启用了剪辑。所有的动画和按钮处理都是在这个UIImageView子类中完成的,而 startFloating 消息是根据需要从一个单独的类发送的。

So I've got a problem with buttons and animations. Basically, I'm animating a view using the UIView animations while also trying to listen for taps on the button inside the view. The view is just as large as the button, and the view is actually a subclass of UIImageView with an image below the button. The view is a subview of a container view placed in Interface Builder with user interaction enabled and clipping enabled. All the animation and button handling is done in this UIImageView subclass, while the startFloating message is sent from a separate class as needed.

如果我没有动画, buttonTapped:消息被正确发送,但在动画期间它不会被发送。我也试过实现 touchesEnded 方法,并发生相同的行为。

If I do no animation, the buttonTapped: message gets sent correctly, but during the animation it does not get sent. I've also tried implementing the touchesEnded method, and the same behavior occurs.

UIImageView子类init该按钮填充一种颜色,所以我可以看到框架设置正确,这是它):

UIImageView subclass init (I have the button filled with a color so I can see the frame gets set properly, which it does):

- (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;
}

启动动画的动画方法(如果我不叫这个按钮工作正常):

Animation method that starts the animation (if I don't call this the button works correctly):

- (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动画会有效地停用按钮。

  • 停用动画会使按钮生效。

  • <
  • Using the UIView animation effectively disables the button.
  • Disabling the animation causes the button to work.
  • The button is correctly sized and positioned on screen, and moves along with the view correctly.

推荐答案

动画只是眼睛糖。动画滞后于视图的实际移动。动画开始时,按钮已经位于目标点。

The animation is just eye candy. The animation lags behind the actual movement of the view. The button is already at the destination point when the animation starts. You just see a movie of the view/button moving.

如果您想在动画期间点击按钮,则必须自行制作动画。

If you want a button to be clickable during the animation, you'll have to make the animation yourself.

这篇关于iPhone UIView动画禁用UIButton子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆