Problem in Autoresizing subviews in iPhone programmatically
- by Cathy
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.