How to enable my screen to respond to a UITouch only after the user is prompted with a message in my iOS app?

StackOverflow https://stackoverflow.com/questions/13756531

Question

I need to enable my screen to respond to a user's touch, but only after they are prompted by a message that appears via an MBProgressHUD. I realize that I need to implement the

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

method, but as I said, I need to do this only when the user has been prompted with a message, and not before. Can this be done, and if so, how?

Was it helpful?

Solution

Just use a Boolean flag called userHasRespondedToMessage. Set it to NO until the user has responded to the message. Then, in your touches method, if the boolean is no, just return instead of handling the touch. Or any other way you want to enable or disable tocuhes.

OTHER TIPS

That's depend on your case. But, here is the general way to handle the touch. When, you need to enable/disable the touch in view, you need to enable/disable it like that:

BOOL wantWhatTouch = NO.//or yes depend on you
[self.view setUserInteractionEnabled:wantWhatTouch];

Above code will disable touch on your view.

So, if now you want to enable touch again. Just at the event when you remove/disable your prompt message, just enable it again...Say, you use a button to remove/hide your alert, then just do it:

[self.view setUserInteractionEnabled:YES];

So, you'll find your touch working again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top