调整UIView的大小,但不调整SubViews的大小 [英] UIView resizing but not the SubViews

查看:98
本文介绍了调整UIView的大小,但不调整SubViews的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIView(v1):

I have an UIView (v1):

 ---------------
|   ---------   |
|  |         |  |
|  |         |  |
|  |         |  |
|  | UIImage |  |     
|  |  View   |  |
|   ---------   |
|    UIView     |
 ---------------

使用UIImageView(img1)作为子视图.

With an UIImageView (img1) as subview.

当我要调整UIView的大小时:

When I'm going to resize the UIView:

int img1int = v1.frame.size.height+(img1.frame.size.height - img2.frame.size.height);
v1.frame = CGRectMake(v1.frame.origin.x, v1.frame.origin.y, v1.frame.size.width, img1int+20);

图像随视图调整大小,但是我只想调整视图大小,并让图像具有正常高度.

The image resize with the view, but I want to just resize the view, and let the image with the normal height.

int 是我进行的演算,因为UIView的高度与UIImageView(img1)的高度有关.

The int is a calculus that I made, for the UIView has its height related to the height of UIImageView (img1).

是否知道如何仅调整 UIView 的大小?

Any idea how to resize only the UIView?

非常感谢!

推荐答案

关闭XIB文件中UIView v1属性的"Autoresize Subviews".

Turn off "Autoresize Subviews" on your UIView v1 attributes in the XIB file.

默认情况下已选中.

这适用于您上面的应用.另外,如果您希望某些孩子自动调整大小,而又不希望它们自动调整大小,则可以在每个孩子上禁用自动调整高度/宽度(自动调整大小"框中的红色箭头.

This works for your app above. Alternatively, if you wanted some children to auto-resize and some not, then on each child you can disable the auto-size height/width (the red arrows within the "Auto-sizing" box.

您的UIImageView随后将停止调整大小.

Your UIImageView will then stop resizing.

这篇关于调整UIView的大小,但不调整SubViews的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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