4

在我的一个视图中的项目中,我想禁用一个按钮之外的所有视图,所以我正在使用

[self.view setUserInteractionEnabled:NO];

因为我有很多组件,所以很难启用和禁用每个组件,所以我正在使用它。

但我想启用一个按钮有很多按钮。

4

4 回答 4

3

根据 XLC 你可以这样做

for (UIView *view in [self.view subviews])
    {
        if (view.tag==101)// set your button tag that you don't wont disable
            [ view setUserInteractionEnabled:YES];
        else
            [ view setUserInteractionEnabled:NO];
    }
于 2013-09-13T03:56:42.147 回答
1

尝试这个:

for (UIView *viewButton in [self.view subviews]) 
{
 if ([viewButton isKindOfClass:[UIButton class]]) //In case you want check only for the buttons.
   {
    if (viewButton.tag==1)//Make sure that you have already set the tag=1 for the button,which you don't want to disable
    {
    [viewButton setUserInteractionEnabled:YES];
    }
    else
    {
    [viewButton setUserInteractionEnabled:NO];
    }
   }
}
于 2013-09-13T04:40:50.900 回答
1

试试这个希望这对你有帮助

for (id subview in [self.view subviews])
{
   if ([subview isKindOfClass:[UIButton class]]&&[subview tag]==1)
   {
         [子视图 setUserInteractionEnabled:YES];
   }
   别的
   {
         [子视图 setUserInteractionEnabled:NO];
   }
}
于 2013-09-13T04:57:58.273 回答
0

如果您使用[self.view setUserInteractionEnabled:NO]; Then 您的整个视图将被禁用,包括子视图。所以最好循环所有子视图并根据要求禁用和启用。

于 2013-09-13T03:49:28.020 回答