简体   繁体   中英

Resizing subview with superview's frame change

I have a UIImageView aSuper; This view is changing its sizes when i flip it ie it is taking sizes of next frame and next frame and so on.

Now this UIImageView contains a subview which is also imageview. I will call it bSubView.

Now i want to resize this bSubView every time its parent's view frame changes.

Code is :- Here invisibleView is subview and viewHolder is parent view. parent view is changing right but problem is with subview.

 UIImage *image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageString1]]];

            UIImageView *viewHolder=[[UIImageView alloc] initWithFrame:CGRectMake(510, 200, 20, 20)];

              invisibleView=[[UIImageView alloc] init];
              invisibleView.image=image;               
              invisibleView.frame=viewHolder.bounds;

            viewHolder.autoresizesSubviews=YES;
            [ invisibleView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
            invisibleView.contentMode=UIViewContentModeCenter;                
            viewHolder.image=[UIImage imageNamed:@"EmptyPlanet"];                  
            [viewHolder addSubview:invisibleView];  

            [self.view addSubview:viewHolder];

Many Thanks in advance.

you can use the inherited method -(void)layoutsubviews

This method is called on the super view when its frame changes. In that method you can configure your subviews

Another option is to use autolayout when configuring the subviews.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM