|Aug 1, 2008, 04:48 PM||#1|
I need a button that changes state in an animated way when the user touches it.
I have spent quite a bit of time going down the "make a UIImageView-derived control respond to touches" road with no success. I can get it to display correctly and to animate correctly, but not to respond to touches.
So I changed approaches. I am now using a UIButton-derived control. UIButton inherits UIControl, which UIImageView is not. So UIButton has an addTarget: action:... method. I figured I could use this method to capture the touch event and just add a UIImageView as a subview of the button.
No such luck. Now I get the touch events, but the image doesn't display or animate...
|Aug 1, 2008, 04:59 PM||#2|
So now I can get the UIImageView to appear as the subview of the button (I had to initialize it with a rect relative to the button, not the container, duh ), but it is eating all the touch events!
When I used a UIImageView-derived class, I couldn't BEG it respond to touch events, they always flowed to the control behind it.
Now that I stick a UIImageView directly on a button, it is eating all of the events! Me no like.
|Aug 1, 2008, 05:33 PM||#3|
OK. So here's the punt of the week:
I created a UIImageView derived class to handle the drawing and animation, etc. Then, in the initialization of said class, I create a UIButton object and lay it over the UIImageView, like so:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 25)];
[button addTarget:self action:@selector( touchedImage: ) forControlEvents:UIControlEventTouchUpInside];
So now the selector set up for the UIButton control handles the touch event and the UIImageView handles the drawing and animating.
I'm not real happy with it. Feels a little duct-tape-ish. But it works like a charm...
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|5 questions (QuickTime, Core Animation, Buttons, and Themes)||macosus||Mac Programming||2||Aug 27, 2011 10:53 PM|
|Animation Desk for iPhone - Anyone can be an animator. Any idea matters. (New Video)||swopes||iPhone and iPod touch Apps||4||Jul 24, 2011 10:59 AM|
|Animated button problem||dchero||Design and Graphics||5||Jun 9, 2011 05:31 PM|
|zoom animation using animation with block based methods||ashwinr87||iPhone/iPad Programming||4||Apr 20, 2011 10:24 AM|
|Animate buttons in a cell||mrl72||iPhone/iPad Programming||2||Jan 13, 2011 10:33 AM|
All times are GMT -5. The time now is 07:11 PM.