Frage

I have a UIImageView that I am able to move in my View by dragging it. The UIImageView is contained inside my main UIView. What I am trying to determine is the center point (CGPoint) of the UIImageView after the user has stopped dragging it. I have the following code:

CGRect frame = _imageView.frame;
CGPoint newCenterPoint = _imageView.center;

NSLog(@"The old center point for the UIImageView is: %@", NSStringFromCGPoint(newCenterPoint));

newCenterPoint.x = frame.origin.x + frame.size.width/2;
newCenterPoint.y = frame.origin.y + frame.size.height/2;

NSLog(@"The new center point for the UIImageView is: %@", NSStringFromCGPoint(newCenterPoint));

With my above code, I notice that the values for newCenterPoint are not updated. Can anyone see what it is I am doing wrong, and what I can do to find the center of the UIImageView after the user has finished moving it?

Thanks in advance to all who reply.

War es hilfreich?

Lösung

When you have finished moving the view, both the frame and center properties have already been updated. So you don't need to do any calculation, you just read the value.

What you code does is to print the new value of center, then calculate the center from the frame. They are, and should be, the same thing.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top