2

我正在开发一个通用应用程序,其中有一个 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;
4

2 回答 2

1

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

[现金大小ToFit]

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

于 2012-05-04T15:05:31.030 回答
0

I agree with @Inturbidus that it's probably another transparent view covering part of the button. I find the best way to troubleshoot this is to change the background color on all my other views (scrollviews, etc) to make sure they are behaving like I think they are. Sometimes it will surprise you when you see where they are actually positioned with background color turned on.

于 2012-05-04T15:11:58.480 回答