Search code examples
iphoneobjective-ccoordinate-transformation

coordinate transform of TouchImageView in iOS


I want to know the final coordinate of predefined 2 points in TouchImageView. 1. If I just move the touchimageview, these codes are okay. 2. But if I scale or rotate touchimageview, the ptLeft and ptRight are not correct.


CGPoint ptLeft  = CGPointMake (100, 100);  
CGPoint ptRight = CGPointMake (200, 200); 
TouchImageView *touchView = [[TouchImageView alloc] initWithFrame:rect];

....
....

/***** get the coordinate after TouchImageView has been scaled or rotated *****/
ptLeft  = CGPointApplyAffineTransform(ptLeft, touchView.transform);  
ptRight  = CGPointApplyAffineTransform(ptRight, touchView.transform);

Here is the touchimageview source code - TouchImageView source code


Solution

  • I'd use the UIView methods convertPoint:fromView: or convertPoint:toView:. Something like:

    ptLeft = [touchView convertPoint:ptLeft toView:[touchView superview]];

    (The latter argument should the view you want to have the point in. It looks like you're trying to get it in the superview, but you might want to use self.view or nil or something else instead.)