Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

iphone - Convert points from image to UIImageView points, contentMode-aware

Let's say I have an image (e.g. 1024 x 768 px) which is displayed in a UIImageView (e.g. 300 x 300 px). Now, I'd like to convert a point from the image, e.g. the position of a person's nose (x: 500, y:600), to the corresponding point on the UIImageView with its contentMode taken into account.

If the contentMode is fixed at UIViewContentModeScaleToFill, conversion will be easy. But if it's UIViewContentModeScaleAspectFit, things getting more complex.

Is there an elegant way to achieve that? I don't really want to calculate that for every single contentMode (more than 10, I think).

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Today, I've had some spare time to put together my solution to this problem and publish it on GitHub: UIImageView-GeometryConversion

It's a category on UIImageView that provides methods for converting points and rects from the image to view coordinates and respects all of the 13 different content modes.

Hope you like it!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...