Re: How to assign a method for touch event to a UIImageView?
On Fri, 24 Jun 2011 22:26:42 +0200, Jonathan Chac?n Barbero tyflos2...@gmail.com said: I want to execute a method when the user touches a UIImageView. In my book, I actually give a solution to this (in the Touch Delivery section of the Touches chapter): set the UIImageView's userInteractionEnabled to YES and attach a UITapGestureRecognizer to it or to its superview. If you attach the UITapGestureRecognizer to the superview, you can use hit-testing to determine whether the UIImageView was tapped: CGPoint p = [g locationOfTouch:0 inView:self]; // g is the gesture recognizer UIView* v = [self hitTest:p withEvent:nil]; m. -- matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/ A fool + a tool + an autorelease pool = cool! Programming iOS 4! http://www.apeth.net/matt/default.html#iosbook___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
How to assign a method for touch event to a UIImageView?
Good evening, I want to execute a method when the user touches a UIImageView. I designed my interface without Interface builder tools because I am blind. I can add an action to a UIButton with this code: [myButton addTarget:self action:@selector(onFotoClick:) forControlEvents:UIControlEventTouchUpInside]; but this code doesn't work with an UIImageView. How can I do this with this class? thanks Regards Jonathan Chacón Barbero Accessibility, usability and new technologies consultant Phone: +34 679953948 e-Mail: jonathan.cha...@telefonica.net Blog: http://www.programaraciegas.es Twitter: http://www.twitter.com/jonathanchacon LinkedIn: http://es.linkedin.com/in/jonathanchacon Facebook: http://www.facebook.com/jonathan.chacon.barbero Messenger: tyf...@hotmail.com Skype: Tyflos_ FaceTime: jonathan.cha...@telefonica.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to assign a method for touch event to a UIImageView?
On 24 Jun 2011, at 3:26 PM, Jonathan Chacón Barbero wrote: I want to execute a method when the user touches a UIImageView. I designed my interface without Interface builder tools because I am blind. I can add an action to a UIButton with this code: [myButton addTarget:self action:@selector(onFotoClick:) forControlEvents:UIControlEventTouchUpInside]; but this code doesn't work with an UIImageView. How can I do this with this class? I admire your perseverance in programming for iOS though blind. I'm not sure I'd do as well. UIImageView is not a control, so it doesn't have built-in handlers for touches that would feed a target-action pair. You'll have to make a subclass of UIImageView (in my experience it tolerates subclassing well), and add your own touchesBegan/Moved/Cancelled/Ended methods. — F ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to assign a method for touch event to a UIImageView?
On Jun 24, 2011, at 1:36 PM, Fritz Anderson wrote: UIImageView is not a control, so it doesn't have built-in handlers for touches that would feed a target-action pair. You'll have to make a subclass of UIImageView (in my experience it tolerates subclassing well), and add your own touchesBegan/Moved/Cancelled/Ended methods. Yeesh, talk about a sledgehammer approach. You can simply attach a UITapGestureRecognizer to the view, turn on user interaction, and you're done. Or you can use a UIButton without a bezel and show your image in the bezel, and then just wire up the button like you would any other button. Tap detection is built into the system. It's not worth rebuilding that when it's baked into the frameworks. Dave ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to assign a method for touch event to a UIImageView?
You could also create a UIButton and have it take a UIImageView. On Jun 24, 2011, at 3:36 PM, Fritz Anderson wrote: On 24 Jun 2011, at 3:26 PM, Jonathan Chacón Barbero wrote: I want to execute a method when the user touches a UIImageView. I designed my interface without Interface builder tools because I am blind. I can add an action to a UIButton with this code: [myButton addTarget:self action:@selector(onFotoClick:) forControlEvents:UIControlEventTouchUpInside]; but this code doesn't work with an UIImageView. How can I do this with this class? I admire your perseverance in programming for iOS though blind. I'm not sure I'd do as well. UIImageView is not a control, so it doesn't have built-in handlers for touches that would feed a target-action pair. You'll have to make a subclass of UIImageView (in my experience it tolerates subclassing well), and add your own touchesBegan/Moved/Cancelled/Ended methods. — F ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/alex%40webis.net This email sent to a...@webis.net Alex Kac - President and Founder Web Information Solutions, Inc. “Don't forget until too late that the business of life is not business but living.” -- B.C. Forbes, ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to assign a method for touch event to a UIImageView?
Hello Jonathan, There are several ways around this. You can create a transparent UIButton laid out exactly where the image view is (and with the same autoresizing masks), then wiring up its action / target where desirable. Another way is to add a UITapGestureRecognizer on the image view. UIImageView might have its userInteractionEnabled property set to NO, if I am recalling correctly. Besides subclassing, composition might work too! :) -ev On Jun 25, 2011, at 04:26, Jonathan Chacón Barbero wrote: Good evening, I want to execute a method when the user touches a UIImageView. I designed my interface without Interface builder tools because I am blind. I can add an action to a UIButton with this code: [myButton addTarget:self action:@selector(onFotoClick:) forControlEvents:UIControlEventTouchUpInside]; but this code doesn't work with an UIImageView. How can I do this with this class? thanks Regards Jonathan Chacón Barbero Accessibility, usability and new technologies consultant Phone: +34 679953948 e-Mail: jonathan.cha...@telefonica.net Blog: http://www.programaraciegas.es Twitter: http://www.twitter.com/jonathanchacon LinkedIn: http://es.linkedin.com/in/jonathanchacon Facebook: http://www.facebook.com/jonathan.chacon.barbero Messenger: tyf...@hotmail.com Skype: Tyflos_ FaceTime: jonathan.cha...@telefonica.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/ev%40monoceroi.com This email sent to e...@monoceroi.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com