小编ben*_*der的帖子

iPhone UIView动画禁用UIButton子视图

所以我的按钮和动画有问题.基本上,我正在使用UIView动画设置动画,同时还试图在视图内的按钮上轻击.视图与按钮一样大,视图实际上是UIImageView的子类,按钮下方有一个图像.该视图是在Interface Builder中放置的容器视图的子视图,启用了用户交互并启用了剪切.所有动画和按钮处理都在此UIImageView子类中完成,而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;
}
Run Code Online (Sandbox Code Playgroud)

启动动画的动画方法(如果我不调用此按钮可以正常工作):

- (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];
}
Run Code Online (Sandbox Code Playgroud)

所以,要明确:

  • 使用UIView动画可以有效地禁用按钮.
  • 禁用动画会使按钮起作用.
  • 按钮尺寸正确并位于屏幕上,并与视图一起正确移动.

iphone cocoa-touch uibutton uiview

7
推荐指数
3
解决办法
4168
查看次数

标签 统计

cocoa-touch ×1

iphone ×1

uibutton ×1

uiview ×1