我正在使用以下代码禁用和启用视图....
[self.view setUserInteractionEnabled:NO];
[self.view setUserInteractionEnabled:YES];
如果我这样做,它的所有子视图也会受到影响......所有都被禁用,我该如何只针对特定视图?是否可以?
我正在使用以下代码禁用和启用视图....
[self.view setUserInteractionEnabled:NO];
[self.view setUserInteractionEnabled:YES];
如果我这样做,它的所有子视图也会受到影响......所有都被禁用,我该如何只针对特定视图?是否可以?
完全相同,假设您的其他视图是成员或者您可以遍历self.view
的子视图数组,如下所示:
MyViewController.h
UIView* otherView;
我的视图控制器.m
otherView.userInteractionEnabled = NO; // or YES, as you desire.
或者:
for (int i = 0; i < [[self.view subviews] count]; i++)
{
UIView* view = [[self.view subviews] objectAtIndex: i];
// now either check the tag property of view or however else you know
// it's the one you want, and then change the userInteractionEnabled property.
}
迅速UIView
确实具有userInteractionEnabled
使其响应或不响应的属性。要使完整的视图无响应使用代码:
// make screen unresponsive
self.view.userInteractionEnabled = false
//make navigation bar unresponsive
self.navigationController!.view.userInteractionEnabled = false
// make screen responsive
self.view.userInteractionEnabled = true
//make navigation bar responsive
self.navigationController!.view.userInteractionEnabled = true
for (UIView* view in self.view.subviews) {
if ([view isKindOfClass:[/*"which ever class u want eg UITextField "*/ class]])
[view setUserInteractionEnabled:NO];
}
希望能帮助到你。快乐编码:)
最好的选择是使用Tag
视图的属性而不是迭代它的所有子视图。只需将标签设置为您要禁用交互的子视图,然后使用下面的代码访问它并禁用交互。
// considering 5000 is tag value set for subView
// for which we want to disable user interaction
UIView *subView = [self.view viewWithTag:5000];
[subView setUserInteractionEnabled:NO];