문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top