0
votes

I am trying to run an animation which uses the position of an item in a UIScrollView for the destination coordinates. I am able to target the destination position without changing the scrollview by using the following line of code:

CGPoint endPoint = [dest_image.superview convertPoint:dest_image.frame.origin toView:nil];

The endPoint is used for the animation destination and the dest_image is the UIImageView in the scrollview.

In some cases, I need to offset the scrollview to show the target UIImageView before running the same animation. I use the following statement to do so:

[self.scrollView setContentOffset:CGPointMake(dest_image.frame.origin.x, dest_image.frame.origin.y) animated:YES];

However, when I try to get the absolute position using the same endPoint code above, the target is offscreen. How is it possible to get the absolute position (in self.view coordinates) of the target ImageView in the scrollview after changing the contentOffset?

Thanks in advance!

1

1 Answers

0
votes

When you pass nil to -[UIView convertPoint:toView:] you're converting dest_image.frame.origin into dest_image.superview.window coordinate space. You should pass self.scrollView to convert it into that coordinate space instead.