Problem in Autoresizing subviews in iPhone programmatically

Posted by Cathy on Stack Overflow See other posts from Stack Overflow or by Cathy
Published on 2010-05-20T12:20:16Z Indexed on 2010/05/20 12:30 UTC
Read the original article Hit count: 557

Filed under:
|

Hi,

I have created a UIViewController and a UIView with two UIButtons in it.

self.view = [[UIView alloc]initWithFrame:CGRectMake( 0,0,320,480)];
self.view.autoresizesSubviews = YES;


 self.view.backgroundColor = [UIColor redColor];
UIView *view;
view = [[UIVew alloc]initWithFrame:CGRectMake(0,0,320,480)];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIButton *button1;
button.frame = CGRectMake(100,130,120,50);
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:button];
[controller addSubview:view];






-(void)buttonAction:(id)sender
{
 //I have created another view for a purpose
 [view removeFromSuperview];
  UIView *view_obj;
**view_obj.backgroundColor = [UIColor greenColor];** 
view_obj.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:view_obj];  
}

Problem: When I change the orientation into landscape the view which has the button is resized but when i click on the button the view with the blueColor is displayed without autoresized. Where i can see half as root view in redColor and half as the subview in greenColor.I have also overrided the ShouldAutoRotate method and done this project programmatically. Please do reply me.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about screen-orientation