Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User interaction disabled for view but enabled for subviews (UIButtons)

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;
like image 524
Willster Avatar asked Jan 17 '11 14:01

Willster


2 Answers

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.

like image 200
Kenny Wyland Avatar answered Oct 25 '22 02:10

Kenny Wyland


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;
}
like image 25
atulkhatri Avatar answered Oct 25 '22 03:10

atulkhatri