Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 1, 2008, 03:48 PM   #1
caldwelljason
macrumors member
 
Join Date: Jul 2008
Animated button

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...

Any thoughts?
caldwelljason is offline   0 Reply With Quote
Old Aug 1, 2008, 03:59 PM   #2
caldwelljason
Thread Starter
macrumors member
 
Join Date: Jul 2008
Touch events

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.
caldwelljason is offline   0 Reply With Quote
Old Aug 1, 2008, 04:33 PM   #3
caldwelljason
Thread Starter
macrumors member
 
Join Date: Jul 2008
One solution

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:

{code}
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 25)];
[button addTarget:self action:@selector( touchedImage: ) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
[button release];
{code}

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...
caldwelljason is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
5 questions (QuickTime, Core Animation, Buttons, and Themes) macosus Mac Programming 2 Aug 27, 2011 09: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 09:59 AM
Animated button problem dchero Design and Graphics 5 Jun 9, 2011 04:31 PM
zoom animation using animation with block based methods ashwinr87 iPhone/iPad Programming 4 Apr 20, 2011 09:24 AM
Animate buttons in a cell mrl72 iPhone/iPad Programming 2 Jan 13, 2011 09:33 AM


All times are GMT -5. The time now is 04:00 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC