User interaction is disabled for viewing, but enabled for subzones (UIButtons)

I have a view that contains several UIButtons that overlay a UIScrollView. I want to prevent user interaction with the overlay view, but not with the UIButtons that are contained in this view.

The reason I group these views into one view is that I can apply alpha change to all the buttons in the view just by changing one property. I just noticed IBOutletCollection in iOS 4.0, but I also need to configure iOS 3.0.

Is there an easier way to achieve this than overriding the following UIView method?

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event; 
+4
source share
3 answers

Unfortunately, if you disable user interaction with the view, user interactions with all subzones will also be disabled. Although not ideal, you just need to do IBOutlets for each of the buttons and adjust them accordingly. To avoid the need to write additional code in the future, in your viewDidLoad you can create an NSArray and drop each button into it. Then, each time you want to change one of the attributes on all these buttons, you can simply iterate over the array and change them. Thus, if you add another button to the group, you only need to update the array, and the rest of the changes will be automatically propagated.

+3
source

Please take a look at this answer: fooobar.com/questions/679366 / ...

Accordingly, you need to override this method in your custom UIView:

 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { UIView *subview = [super hitTest:point withEvent:event]; return subview == self.button ? subview : nil; } 
+1
source

disable only scroll view using scrollView.scrollEnabled = FALSE; when you want the user to allow the use of the button. Turn it on again when you want the user to view scrollView.scrollEnabled = TRUE;

Note: you do not need to disable user interaction with scrolling.

0
source

Source: https://habr.com/ru/post/1335844/


All Articles