为了显示帮助视图,我放了一个后面有一些UIButtons的UIImageView。如何禁用这些按钮的用户交互?如果我触摸这张图片,按钮在后面,它们会响应触摸事件。
图片背景代码:
self.helpBackground = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
self.helpBackground.backgroundColor = [UIColor colorWithWhite:0 alpha:0.75];
self.helpBackground.hidden = YES;
[self.view addSubview:self.helpBackground];我使用了self.helpBackground.userInteractionEnabled = NO;但不起作用。
谢谢。
发布于 2014-09-03 21:55:04
将您的按钮放入一个数组中,循环遍历并禁用它们:
NSArray *buttonsArray = @[yourButton1, yourButton2];
for (UIButton *button in buttonsArray) {
button.enabled = NO;
}当您想要启用它们时,只需再次循环并将enabled设置为YES
发布于 2014-09-03 21:58:07
在您的helpView(imageview)中保留一个标记,并添加以下代码
for (UIView *view in self.view.subviews) {
if (view.tag != yourViewTag) {
view.userInteractionEnabled = NO;
}
} 在删除帮助屏幕之后,使用以下代码
for (UIView *view in self.view.subviews) {
view.userInteractionEnabled = YES;
} 发布于 2014-09-03 22:25:54
您可以尝试查看下面出现的solution..When帮助图像视图
for (UIView *view in [self.view subviews])
{
if (view isKindOfClass:[UIButton Class])
{
view.userInteractionEnabled = NO;
}
else
{
view.userInteractionEnabled = YES;
}
}
////After dismissing the help screen you can
for (UIView *view in [self.view subviews])
{
if (view isKindOfClass:[UIButton Class])
{
view.userInteractionEnabled = YES;
}
} /(OR)只需执行以下操作
self.view.userInteractionEnabled=YES;希望它能帮助你..
https://stackoverflow.com/questions/25645744
复制相似问题