Disable User Interaction with a ViewController tem

2019-07-23 01:31发布

I use a Main ViewController and a Navigation ViewController. If the user uses the Navigation, the Navigation ViewController takes 80% of the Screen and the Main ViewController the other 20%. In this Case the user shouldn't interact with the Main ViewController.

How could i disable the interaction with the Main ViewController temporarily?


EDIT: This declares the further Problems:

This works partially fine. Now the User can't interact with the MainViewController if the Navigation is open, but this generates 2 other Problems:

Problem: The User can interact with NavigationView at the place (20% of the App on the right side) of the MainView. The user shouldn't do an interaction worth the lower NavigationController (Navigation)

Problem: The User can't drag on the 20% of the MainView to close the NavigationView and open the MainView complete.

I think it could be a reason to disable the interaction with all Objects with be hierarchical under the MainView. Is this possible if i do this in a function of another ViewController? The difficulty is, that i should do this for different kinds of "MainViews". Sometimes it includes only a TableViewController, sometimes its a cluster of UIButtons, and so on.

2条回答
放荡不羁爱自由
2楼-- · 2019-07-23 01:54

mainViewController.view.userInteractionEnabled = FALSE should work for you.

This shuts off the view from responding to touches.

查看更多
Deceive 欺骗
3楼-- · 2019-07-23 02:15

Now i like to show you my Solution, maybe someone got an similar problem. (I hope its ok, that i show this in a new Post and not an Edit, otherwise i cant check it as solved)

If the MainViewContent shouldn't be user interacted:

CGRect viewSize = self.centerView.frame;
UIView *disableInteractionView = [[UIView alloc] initWithFrame:CGRectMake(viewSize.origin.x, (viewSize.origin.y + 44.0), viewSize.size.width, (viewSize.size.height - 44.0))];
disableInteractionView.backgroundColor = [UIColor clearColor];
disableInteractionView.tag = 1234;
[self.centerView addSubview:disableInteractionView];

If the MainViewContent is free for interaction:

[[self.centerView viewWithTag:1234] removeFromSuperview];
查看更多
登录 后发表回答