I have a view which contains several UIButtons which overlays a UIScrollView. I want to prevent user interaction on the overlay view but not on the UIButtons that are contained within that view.
The reason why I am grouping these views into a single view is such that I can apply an alpha change to all the buttons in the view by just changing a single property. I have just noticed the IBOutletCollection in IOS 4.0 but I need to also target IOS 3.0.
Is there a more simple way to achieve this than overriding the following UIView method?
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event;
Unfortunately if you disable user interaction with a view then user interactions with all subviews are also disabled. While not ideal, you'll just need to make IBOutlets for each of the buttons and adjust them accordingly. To avoid having to write to much additional code in the future, in your viewDidLoad you can create an NSArray and toss each of the buttons into it. Then every time you want to change one of the attributes on all of those buttons, you can just loop over the array and change them. That way if you add another button to the group you only need to update the array and the rest of the changes will automatically propagate.
Please have a look at this answer: https://stackoverflow.com/a/13414182/2082569
According to this 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;
}
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