我正在使用以下代码禁用和启用视图...
[self.view setUserInteractionEnabled:NO];
[self.view setUserInteractionEnabled:YES];如果我这样做,所有的子视图也会受到影响……全部禁用,如何仅针对特定视图执行操作?有可能吗?
发布于 2012-08-31 18:45:11
完全相同,假设您的另一个视图是成员,或者您可以遍历self.view的子视图数组,如下所示:
MyViewController.h
UIView* otherView;MyViewController.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.
}发布于 2015-12-03 20:12:07
在swift UIView中,确实有userInteractionEnabled属性来使其响应或不响应。要使full View无响应,请使用代码:
// 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发布于 2012-08-31 18:44:41
for (UIView* view in self.view.subviews) {
if ([view isKindOfClass:[/*"which ever class u want eg UITextField "*/ class]])
[view setUserInteractionEnabled:NO];
}希望能有所帮助。快乐编码:)
https://stackoverflow.com/questions/12213663
复制相似问题