4

I'd like to move a view from a scrollview to a uiview.

I'm having trouble changing it's center(or frame) so that it remains in the same position in screen (but in a different view, possibly the superview of scrollview).

How should I convert the view's center/frame?

Thank you.

EDIT:

   CGPoint oldCenter = dragView.center;                                                                         
    CGPoint newCenter = [dragView convertPoint: oldCenter toView: self.navigationView.contentView];    
    dragView.center = newCenter;
    [self.navigationView.contentView addSubview: dragView];

I can also use (NSSet*) touches since i'm in touchesBegan:
I was having hard time to make it work but the doc wasn't so clear to me.

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
eugene
  • 39,839
  • 68
  • 255
  • 489

1 Answers1

3

You can use convertPoint:toView: method of UIView. It is used to convert a point from one view's coordinate system to another. See Converting Between View Coordinate Systems section of UIView class reference. There are more methods available.

-edit-

You are using the wrong point when calling convertPoint: method. The given point should be in dragView's coordinate system where as dragView.center is in its superview's coordinate system.

Use the following point and it should give you the center of dragView in its own coordinate system.

CGPoint p;
p = CGPointMake(dragView.bounds.size.width * 0.5, dragView.bounds.size.height * 0.5);
murat
  • 4,893
  • 4
  • 31
  • 29
  • ah, i've tried using it, and the converted point didnt seem correct and was wondering if that's what I needed, I'll look into it again and come back – eugene Dec 25 '10 at 13:00
  • I have edited my answer an included the point you need to use to convert. – murat Dec 25 '10 at 13:24