UIView Frame Size Didn't Change UIImageView Placed inside it

你离开我真会死。 提交于 2020-01-02 19:30:10

问题


I'm making a picture in a frame and then user can resize the frame size in runtime. For this purpose I've made a custom UIView in my main UIViewController and inside this UIView I've placed 2 UIImageView. In Document Outline Pane of xCode it's hierarchy is:


View
|--ImageView
|--ImageView

I'm using this line of code to change size of UIView under different conditions it'll resize accordingly:

self.imageObject.frame = CGRectMake(self.imageObject.frame.origin.x , 
                                    self.imageObject.frame.origin.y, 
                                    200, 
                                    200);

imageObject is my UIView. When I run it the size of the UIView changes but UIImageView size remains the same. I've also tried doing the same for my UIImageView but it didn't work.


回答1:


You can also Try This :-

imageView.frame = CGRectMake(0,0,imageObject.frame.size.width, imageObject.frame.size.height);
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.imageShw.contentMode = UIViewContentModeScaleAspectFit;



回答2:


First You can try,

self.imageObject.autoresizesSubviews = YES;

Otherwise to get the subviews to resize, you can add autoresizing mask to the subviews, to the two imageviews in your case:

imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin   |
                             UIViewAutoresizingFlexibleRightMargin  |
                             UIViewAutoresizingFlexibleTopMargin    |
                             UIViewAutoresizingFlexibleBottomMargin |
                             UIViewAutoresizingFlexibleWidth        |
                             UIViewAutoresizingFlexibleHeight;

Check UIView documentation for more details.




回答3:


Try:

imageView.frame = CGRectMake(0,
                             0,
                             imageObject.frame.size.width, 
                             imageObject.frame.size.height);
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | 
                             UIViewAutoresizingFlexibleWidth;


来源:https://stackoverflow.com/questions/27599275/uiview-frame-size-didnt-change-uiimageview-placed-inside-it

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