|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|
|iPhone 5 black screen. Power button and home button not working.||brian4la||iPhone Tips, Help and Troubleshooting||2||Jun 25, 2014 06:54 PM|
|My iOS Game - Press The Button - Red Button||danielmcfarland||iPhone and iPod touch Apps||0||Mar 24, 2014 04:51 PM|
|iOS 7 beta 6 - Phone not waking on first attempt (Power button or Home button)||DDustiNN||iOS 7||9||Sep 30, 2013 08:03 PM|
|Iphone 4 silent button/volume button problems and more||JohnoFisher||iPhone Tips, Help and Troubleshooting||0||Sep 28, 2013 05:07 AM|
|iPhone 4 Sleep/wake button, vibrate button, and volume button not responsive||McEggrolls||iPhone||6||Sep 20, 2012 10:16 AM|
All times are GMT -5. The time now is 03:52 PM.