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

Similar Threads
thread Thread Starter Forum Replies Last Post
iPhone 5 black screen. Power button and home button not working. brian4la iPhone Tips, Help and Troubleshooting 2 Jun 25, 2014 05:54 PM
My iOS Game - Press The Button - Red Button danielmcfarland iPhone and iPod touch Apps 0 Mar 24, 2014 03:51 PM
iOS 7 beta 6 - Phone not waking on first attempt (Power button or Home button) DDustiNN iOS 7 9 Sep 30, 2013 07:03 PM
Iphone 4 silent button/volume button problems and more JohnoFisher iPhone Tips, Help and Troubleshooting 0 Sep 28, 2013 04:07 AM
iPhone 4 Sleep/wake button, vibrate button, and volume button not responsive McEggrolls iPhone 6 Sep 20, 2012 09:16 AM

Forum Jump

All times are GMT -5. The time now is 11:43 PM.

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

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