iOS Aspect填充图像大小调整内容与左/上边缘对齐 [英] iOS Aspect Fill Image Resizing with Content Aligned to Left/Top Edge

查看:498
本文介绍了iOS Aspect填充图像大小调整内容与左/上边缘对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iOS-7开发通用应用程序。这个特殊问题仅适用于iPad。我想将图像放置为视图控制器的根视图的背景,即图像应该填满整个屏幕。 1x图像的大小:768x1024。这适用于纵向方向,因为iPad的非视网膜分辨率也是768x1024的纵向。在横向,但图像不适合。我尝试过使用ScaleToFit,但由于图像的纵横比没有保留,我不能使用ScaleToFit(它们是图像中的东西,当在两个轴上没有按比例缩放时看起来很奇怪)。 AspectFill调整大小似乎最适合我的需要,但它们是一个小问题。如Apple文档中所定义内容被调整为完全填充边界矩形,同时仍然保留内容的方面。内容以其超出的轴为中心。。我不希望内容在超出的轴中居中,我希望它与顶部/左边缘对齐。

I am developing a universal app for iOS-7. this particular question is specific to iPad only. I want to place an image as background of root view of a View Controller i.e. the image should fill the whole screen. The 1x image has size:768x1024. This works for Portrait orientations as non-retina resolution of iPad is also 768x1024 in portrait. In Landscape however the image does not fit. I have tried using ScaleToFit but since aspect ratio of image is not preserved I can not use ScaleToFit(their are things in image which look odd when not scaled proportionally in both axis). AspectFill resizing seems most suitable for my need, but their is a small problem. As defined in Apple Documentation "The content is resized to completely fill the bounds rectangle, while still preserving the aspect of the content. The content is centered in the axis it exceeds.". I do not want the content to be centered in axis in which it exceeds, I want it to be aligned to top/left edge.

基本上我想要两件事:


  • Aspect Fill

  • 内容在左/上边缘保持对齐。

是否可以实现此目的。任何代码片段都会很棒。

Is it possible to achieve this. Any code-snippet will be great.

谢谢

推荐答案

你将必须子类化View Controller的视图并手动缩放和对齐。

You will have to subclass the View Controller's view and manually scale and align.

查看这个答案。

调整 imageViewXOrigin imageViewYOrigin 以便根据需要调整。

Adjust imageViewXOrigin and imageViewYOrigin to align however you want.

这篇关于iOS Aspect填充图像大小调整内容与左/上边缘对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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