【问题标题】:Button unselectable after UIView animationUIView 动画后按钮无法选择
【发布时间】:2013-12-25 07:09:55
【问题描述】:

在我的应用程序中,我有一个带有 UIButton 子视图的 UIView。在 viewDidLoad 我隐藏了一个自定义视图。当用户单击某个按钮时,视图应与该按钮一起出现。它工作正常,但按钮不再可选择。动画结束后我无法再与它互动。有什么问题?这是代码。 ViewDidLoad:

view = [[UIView alloc] initWithFrame:CGRectMake(-150, 0, 150, [[UIScreen mainScreen] bounds].size.height)];
[view setBackgroundColor:[UIColor clearColor]];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:view.frame];
imageView.image = effectImage;
[view addSubview:imageView];
[self.view addSubview:view];

UIButton *remove = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 170, [[UIScreen mainScreen] bounds].size.height)];
    [remove setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:remove];

另一种方法的动画:

[UIView animateWithDuration:0.5 animations:^{
        [view setFrame:CGRectMake(150, 0, 150, [[UIScreen mainScreen] bounds].size.height)];
    }];

我个人没有发现任何问题。有什么帮助吗?

【问题讨论】:

  • 您是否将目标添加到删除按钮?否则,任何点击都不起作用。
  • 是的,我做到了。不工作。

标签: ios objective-c uiview


【解决方案1】:

您的UIViewUIButton 似乎重叠了 20 像素,因为按钮的宽度为 170,并且视图的 x 坐标为 150。因此您可能需要将按钮放在前面。

[self.view bringSubviewToFront:remove];

[UIView animateWithDuration:0.5 animations:^{
    [view setFrame:CGRectMake(150, 0, 150, [[UIScreen mainScreen] bounds].size.height)];
    [self.view sendSubviewToBack:view];
}];

【讨论】:

    猜你喜欢
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-17
    • 2018-07-08
    • 1970-01-01
    相关资源
    最近更新 更多