pratik
pratik

Reputation: 4489

iPhone + detect tap of disabled UIControl

I am developing In App purchase for one existing application. Scenario is something like I have a feature in application (which contain UITextField control), which is initially disabled and when user taps on that UITextField, it shows the message to unlock and buy that feature and once its done, UITextField will be enable.

But the problem is that since UITextField is disabled initially, I am not able to detect any tap on that, so I am not able to get any event where I can code for In App purchase functionality.

OR

If its not possible to detect the tap of disabled UIControl, what can be other option to achieve the above functionality.

Please help.

Regards, Praik

Upvotes: 0

Views: 1774

Answers (4)

How is a user going to know to press a disabled button? You are better off offering a non-disabled button that makes clear what will happen when you press it.

Upvotes: 0

corprew
corprew

Reputation: 2001

Put an invisible button over the text area by making a button like this:

    UIButton* button = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
    button.frame =CGRectMake(your parameters here);
    button.showsTouchWhenHighlighted=YES; // handy for debugging
    [button addTarget:self action:@selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];

and adding it as a subview. Depending on what you're trying to achieve and what your UITextField is contained in, what you need to add it to may differ.

Upvotes: 2

kennytm
kennytm

Reputation: 523614

It is not easy to detect taps of disabled UIControl directly unless you subclass it and hook the -touchesXXXXX:withEvents: methods.

However, you can layer an active and transparent UIControl on top of the disabled one to takeover the tap. Remove the transparent control once the purchase is done.

Upvotes: 0

Julien
Julien

Reputation: 9442

Of what I remember, subviews of disabled views are also disabled, so I guess your "feature" is a disabled view. You can try to put your UIControl on a view which is not disabled (the UIWindow for example, or any subview) and bring it on top. Not 100% sure but i think it should work.

Upvotes: 0

Related Questions