iPhone - 嵌套在UIView中的UI按钮不会响应该视图的动画后的触摸

Zig*_*rth 6 iphone animation uibutton uiview

我有一个带有UIButton的UIView(视图B).

我将此视图B添加到主视图边界之外的区域中的主视图(视图A),而不是使用UIView动画为其设置动画.

在UIView动画完成后,View B现在位于View A之上,因此按钮可见,按钮不响应触摸...我以前从未见过这个但是这是我用新的第一个应用程序iOS(iOS 5).有任何想法吗?

提前致谢.

Nie*_*els 2

这就是你所描述的情况吗?因为它看起来工作得很好。您是否检查了 UIView 上的 userInteractionEnabled 是否设置为 YES?

- (void)buttonPressed:(UIButton*)button
{
    NSLog(@"button pressed");
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, -100, 100, 100)];
    view.backgroundColor = [UIColor blackColor];

    UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"Button" forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 10, 100, 20);
    [view addSubview:button];

    [self.view addSubview:view];

    [UIView animateWithDuration:0.5 animations:^{
        view.transform = CGAffineTransformMakeTranslation(0, 100);
    }];

    [view release];
}
Run Code Online (Sandbox Code Playgroud)