Sunday, 2 June 2013

Enable / Disable Touch Events on UIImageView Object

Enable / Disable Touch Events on UIImageView Object

I've read answers to many questions that dealt with enabling / disabling touch events, but nothing has worked for me, so I'm asking one of my own.
I have a UIImageView object (spot):
// in my view controller header file:
@property (nonatomic, strong) IBOutlet UIImageView *spot;
I override the touchesBegan withEvent method:
// in my view controller .m file:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    // handle when that spot is touched ...
}
And that works fine. For example, I can change the image displayed at the spot when the spot is clicked.
First I wanted to see how to disable touch events on the spot so I tried:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
And that works fine. At certain points, depending on what I want to do, I was able to disable all touch events.
Then I added a button to this view controller and I want the button to be clickable ALWAYS, to have a touch event ALWAYS enabled for the button.
So now my approach to disabling touch events won't work because it's too heavy-handed. It wipes out all touch events anywhere in that view.
I want to disable ONLY the touch event on that spot. I tried:
spot.userInteractionEnabled = NO;
But that didn't work. The spot was still clickable. I also tried:
[spot1 setUserInteractionEnabled:NO];
Also didn't work. I'm quite confused as to why those don't work. My question is:
How can I disable touch events on just this one spot, this one UIImageView object?

No comments:

Post a Comment