繁体   English   中英

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

[英]iPhone - UIbutton nested in UIView does not respond to touch following animation of that view

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

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

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

提前致谢。

这是你描述的情况吗? 因为它似乎工作正常。 您是否检查过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];
}

我不确定这是否已经回答了所以我试了一下,只是为了记录:

检查按钮是否不在任何超级视图的框架之外。

我发现像这样放在外面的按钮可能不起作用。 来想一想,这很奇怪。 当我使用从下面动画的按钮制作视图时,我遇到了这个问题。 在这下面,我有一个灰色的可触摸视图,允许取消。 唯一的问题是1)灰色区域我使用父视图本身和2)我让这个灰色区域缩小,因为子视图动画到位...因此,按钮变得外面,它不起作用。

解决方案是将视图保留为全尺寸,并将另一个添加为灰色,或者使第一个灰色而不缩小(我想避免这种情况的唯一原因是它会使一堆半透明层不是最佳的) 。 然后是按钮顶部的视图。 :)

希望这可以帮助。

如果你通过编程创建了Button,那么你必须这样做: -

myButton.userInteractionEnabled =YES;

希望能帮助到你... :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM