iPad : UIButton需要多次点击尝试才能捕捉到动作



我正在开发一个通用应用程序,其中有一个UIButton,它可以在iPhone上运行良好,但是当我在iPad中单击它时,它需要多次单击尝试才能发生触摸事件。

例如,点击

5-6 次后,它执行点击事件。

下面是UIButton代码。请帮忙。

UIView *footer = [[[UIView alloc] initWithFrame:(CGRectMake(0, 0, self.tableView.frame.size.width, 54))] autorelease];
float buttonWidth = (int)((self.tableView.frame.size.width - 12 - 12) / 3);
float buttonHeight = 44;
if (clientState.Devicetype == 1) // 1=Ipad
    buttonHeight = 90;
cash = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
cash.frame = CGRectMake(6, 10, buttonWidth, buttonHeight); 
[cash setTitle:@"Cash" forState:UIControlStateNormal];
[cash setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled];
[cash addTarget:self action:@selector(handleCash:) forControlEvents:UIControlEventTouchUpInside];
cash.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
if (clientState.Devicetype == 1) // 1=Ipad
{
    cash.titleLabel.font = [UIFont systemFontOfSize:28];    
}
[footer addSubview:cash];
self.tableView.tableFooterView = footer;

您应该检查以确保按钮的大小正确:

[现金大小适合]

我经历过,如果其他视图阻止了它(并且您单击按钮的该部分,它不会触发事件),则需要单击几次,因为您最终按下了未被覆盖的按钮。 因此,请确保按钮顶部没有其他框架/边界,并确保按钮大小正确。

我同意@Inturbidus的观点,这可能是另一个覆盖按钮部分的透明视图。我发现解决此问题的最佳方法是更改所有其他视图(滚动视图等)的背景颜色,以确保它们的行为与我认为的一样。有时,当您看到它们在打开背景颜色的情况下实际放置的位置时,您会感到惊讶。

最新更新