1

I have a custom controller and inside I have a UIImageView ( or a UIButton ). My custom controller is a slider, so basically when touchesEnded is called I want to check the intersection with other components. I can't manage to drag the UIImageView, and if I subclass it, I will have to write all the logic code in the subclass of UIIMage and I don't want that. Is there a way to drag it from my custom controller class?

Thank you.

Cosmin
  • 2,840
  • 5
  • 32
  • 50
  • CGRectIntersectsRect (CGRect rect1, CGRect rect2); use this if two rect/frame intersect or not.. – Inder Kumar Rathore Feb 23 '12 at 11:25
  • Yes, but this code I have to write it in my UIImageView subclass, and I don't want that. I want to have all the logic of my custom controller in the UIControl subclass. – Cosmin Feb 23 '12 at 11:32

2 Answers2

0

I suggest to let each element to manage its own touch events. So the drags in the UIImageView is independent of other events of the parent view.

Community
  • 1
  • 1
ohho
  • 50,879
  • 75
  • 256
  • 383
  • Yes, but I need to check if the UImageView intersects with other components in the control, this means that I have to keep a reference of my control in my UImageView subclass. I don't want that. – Cosmin Feb 23 '12 at 10:51
0

You will most definetly not have to write "all the logic code", that's what subclassing is all about.

So to answer your question not in way you want it but in a way you will have the least work to do:

consider subclassing again. You only have to override three methods and add one iVar.

Please see both answers here: UIView drag (image and text)

Community
  • 1
  • 1
Rok Jarc
  • 18,765
  • 9
  • 69
  • 124
  • I did something else. I use a UIPanGestureRecognizer, and my UIButton is the only one that will accept touches for the gesture recognizer. – Cosmin Mar 28 '12 at 10:40
  • ` -(BOOL)gestureRecognizer:(UIGestureRecognizer*) gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if (touch.view == sliderButton) return YES; return NO; }` – Cosmin Mar 28 '12 at 10:41