(iphone) how to set view.center when detaching a view from the scroll view and adding it to another view?

I would like to move the view from scroll to uiview.

I'm having problems changing its center (or frame) so that it stays in the same position on the screen (but in a different form, possibly in the form of a scroll view).

How do I convert a view center / frame?

Thanks.

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 tags (NSSet*) since I'm in touchesBegan :
I had a difficult time to get it to work, but the doctor was not so clear.

+4
source share
1 answer

You can use the convertPoint:toView: UIView method. It is used to convert points from one coordinate system of a view to another. See the section "Transformation between coordinate systems" in the UIView class reference. More methods available.

-edit -

You are using the wrong point when calling the convertPoint: method. This point should be in the dragView coordinate system, where dragView.center is in its observation coordinate system.

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

 CGPoint p; p = CGPointMake(dragView.bounds.size.width * 0.5, dragView.bounds.size.height * 0.5); 
+3
source

Source: https://habr.com/ru/post/1333331/


All Articles