UIView resizing but not the SubViews

天大地大妈咪最大 提交于 2019-12-02 03:27:50

问题


I have an UIView (v1):

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

With an UIImageView (img1) as subview.

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.

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

Any idea how to resize only the UIView?

Thanks a lot!


回答1:


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

By default this is checked.

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.

Your UIImageView will then stop resizing.



来源:https://stackoverflow.com/questions/9762110/uiview-resizing-but-not-the-subviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!