I am disabling and enabling a view using the following code....
[self.view setUserInteractionEnabled:NO];
[self.view setUserInteractionEnabled:YES];
If I do like this, all it subviews also got affected... All are disabled, how do I do only for particular view? Is it possible?
It's exactly the same, assuming your other view is either a member or you can iterate through self.view
's array of subviews, like so:
MyViewController.h
UIView* otherView;
MyViewController.m
otherView.userInteractionEnabled = NO; // or YES, as you desire.
OR:
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.
}
In swift UIView
do have property userInteractionEnabled
to make it responsive or not. To make full View unresponsive use code:
// 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];
}
hope it helps. happy coding :)
The best option is to use Tag
property of the view rather than iterating all its subviews. Just set tag to the subView which you want to disable interaction and use below code to access it and disable interaction.
// 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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With