iOS - 从 UIImageView 获取 UIImage 的可见部分的框架 [英] iOS - Get framing of Visible part of UIImage from UIImageView

查看:30
本文介绍了iOS - 从 UIImageView 获取 UIImage 的可见部分的框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试像 APP Tinder 那样进行过渡.详情:

I am trying to make a transition like APP Tinder. Detail:

  1. 在屏幕一中,有一个垂直矩形 UIImaveView,其 contentMode = 纵横比填充,因此它隐藏了图像的某些部分以调整纵横比.

  1. In Screen One there is a Vertical Rectangular UIImaveView with contentMode = Aspect Fill, so it hides some portion of Image to adujust Aspect Ratio.

在第二个屏幕(细节屏幕)中必须传递转换后的相同图像,但第二个屏幕中的 ImageView 是方形一.

In Screen Two (Detail Screen) the same image after transition has to to be passed, but the ImageView in Second screen is Square One.

我想做一种变形的过渡,用户应该认为屏幕一中的相同 ImageView 在第二个中变成方形,而不拉伸图像.那么我该怎么办?

I want to make a Morphing kind of Transition in which User should think that the same ImageView from Screen One become square one in Second one without stretching the Image.So What should i do?

目前我正在尝试获取 UIImageView 可见区域中的 UIImage Frame,以便我可以做一些逻辑上的事情来实现这一点.但谁能帮我获取 UIImage 可见部分的框架.

Currently i am trying to get Frame of UIImage that is in visible area of UIImageView so that I can do some Logical stuff to achieve this. but can anyone help me to Get the Frame of Visible Portion of UIImage.

编辑

请查看附件图片以供理解

Please Find out the Attached Image for understanding

推荐答案

我认为这个问题有点含糊:必须在坐标系中指定一个框架.但我认为您正在寻找相对于原始未剪裁图像的矩形.

I think there's a little ambiguity in the question: a frame must be specified in a coordinate system. But I think you're looking for a rect relative to the original, unclipped image.

如果这是对的,那么矩形可以计算如下.假设图像名为image,图像视图为imageView.rect的大小就是图像视图的大小:

If that's right, then the rect can be computed as follows. Say the image is called image, and the image view is imageView. The size of the rect is the size of the image view:

imageView.bounds.size

而且,由于纵横填充将使超大尺寸居中,它的原点是:

And, since aspect fill will center the oversized dimension, it's origin is:

CGPointMake((image.size.width - imageView.bounds.size.width) / 2.0, 0.0);

这篇关于iOS - 从 UIImageView 获取 UIImage 的可见部分的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆