tags:

views:

4322

answers:

3

I've had a lot of users complain that the little "i" info button is difficult to touch on the iPhone. Ok, simple enough -- I just stuck a big-fat invisible button behind it that you can't miss even with the sloppiest of finger touches and, when you touch it, it does the infoButtonAction.

Thing is, I'd like to flash the info button, itself, for about .25 sec, just to give a visual "this is what's going on" type of feedback. I mean, I'm already assuming that you meant to hit the "i" button, so I'm just treating it as if you DID hit it.

I tried this, but it doesn't work:

    UIImage* normalImage = [_infoButton imageForState:UIControlStateNormal];
    UIImage* highlighted = [_infoButton imageForState:UIControlStateHighlighted];
    _infoButton.highlighted = YES;                                          // flash the button
    [_infoButton setImage:highlighted forState:UIControlStateNormal];
    [_infoButton setNeedsDisplay];                                          //* FIXME: No flash?!

    [(AppDelegate*)[[UIApplication sharedApplication] delegate] infoTap];   // do the info action

    _infoButton.highlighted = NO;   
    [_infoButton setImage:normalImage forState:UIControlStateNormal];
    [_infoButton setNeedsDisplay];

Any ideas about how to get the behaviour I want?

(I'm also open to alternate ideas about user feedback, but still curious how I'd do this. Imagine that, instead, I have a "game"/prank where you push the "ok" button and "cancel" flashes, and vice versa, or something equally silly.)

Thanks!

A: 

I don't know exactly what happens in your infotap method, but there doesn't appear to be anything there to cause much of a delay between your first setImage: call and the second. My guess is that things are happening faster than the eye can see. I'd suggest looking at NSTimer to try to put a specific delay there.

Matt Ball
+1  A: 

The problem is that you are marking your button as needing display (calling -setNeedsDisplay is unecessary; the button calls that internally), but then never allowing the run loop a chance to display the new image.

In Cocoa, you could use something like -performClick: but that is not available on the iPhone.

Instead, I suggest you experiment with calling -setSelected: or -setHighlighted: with a delay in between.

Mike Abdullah
Ok, the 44x44 thing solved my meta-problem, but this is the answer for the "main" question that I asked. Thanks!
Olie
+3  A: 

The "i" button should be sized to 44x44 (Apple standard finger size) which can be done in the Interface Builder.

For some animations I'd suggest looking into Core Animation.

epatel
Ah! I had not realized that a new infobutton did not come "out of the box" (when programatically created) as 44x44. Important point; thanks!
Olie
sehugg
I think when I wrote this (and the question was put) one had to create the "i" button in code. Now the button is available in IB.
epatel