如何使用 UIImageView 调整图片大小以便放大和缩小?
在我看来,我有一张图片。这张图片的比例为 3:2,而且分辨率很大。
我在用图像初始化 UIImage 到原始大小然后缩小 UIImageView 以使整个图像在滚动视图中可见时遇到很多麻烦。
该程序仅停留在纵向方向。
不,请不要说只使用 UIWebView。 UIWebView 不允许我在视图加载期间设置内容大小...相反,它只是按任意比例缩小图像,而且我无法找到调整比例值的方法(我不认为这是可能的)。
感谢您的任何回复!我真的很感激他们:D
In my view I have a picture.. The picture has a 3:2 scale and is huge, resolution wise.
I'm having a lot of trouble initializing a UIImage with the image to the original size and then zooming out of the UIImageView so that the entire image is visible within the scrollview.
The program stays only in the portrait orientation.
And no, please don't say to just use UIWebView. UIWebView doesn't let me set the content size during view load...instead, it just zooms out of the image by some arbitrary scale and I couldn't figure out a way to adjust the scale value (I don't think it's possible).
Thanks for any responses! I really appreciate them :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是放置响应捏合缩放的图像的示例。基本上,您将
UIImageView
放置在UIScrollView
中并更改一些设置。当然,正确设置所有委托和 IB 挂钩。
编辑:我刚刚重读了你的问题。该示例中回答您问题的部分是 UIImageView 的框架规范及其
contentMode
设置。Here's an example of placing an image that responds to pinch-to-zoom. Basically, you place the
UIImageView
in aUIScrollView
and change some settings.Of course, set all your delegates and IB hooks properly.
Edit: I just reread your question. The portion of the example that answers your question is the frame specification of the UIImageView and its
contentMode
setting.您几乎肯定不希望在加载时一次性加载“巨大的、分辨率明智的”图像,无论其大小如何。我建议查看一些有关此内容的 Apple 示例代码(从 ScrollViewSuite 会很好,我想说)。
WWDC 最近发布了一段视频,他们在其中实时实现了此类功能(他们有更多的照片查看应用程序,但您也可以很容易地只用一张图像来完成他们所展示的内容),所以也请看一下。
You almost certainly don't want to load your 'huge, resolution wise' image all at once on load regardless of it's scale. I'd suggest checking out some of Apple's sample code on this stuff (starting with ScrollViewSuite would be good, I'd say).
There was also a recent video released from WWDC where they implement this sort of thing live (they have more of a photo viewing app, but you could pretty easily do what they show with just one image too) so take a look for that too.
转到 UIImageView 的属性选项卡。选择“填充方面”或“适合方面”。如果您使用“宽高比填充”,则可能无法显示整个图像。我只是使用“适合的方面”,并将背景设为黑色。
Go to the attributes tab of the UIImageView. Select "aspect to fill" or "aspect to fit". If you use "aspect to fill", you might not show the whole image. I just use "aspect to fit", and make the background black.