siva
siva

Reputation: 251

view width is not changing when i rotate the view

i have created a view in textfield should characters method like this. when i change my view from portrait to landscape my view width is not changing.

  viewForautoCompleteTableView = [[UIView alloc]initWithFrame:CGRectMake(30, 120, 212, 100)];
        viewForautoCompleteTableView.autoresizingMask=UIViewAutoresizingFlexibleWidth;


        [self.view addSubview:viewForautoCompleteTableView];
        viewForautoCompleteTableView.layer.borderWidth=1;
        viewForautoCompleteTableView.layer.borderColor=[UIColor grayColor].CGColor;

thank you

Upvotes: 1

Views: 857

Answers (2)

Saify
Saify

Reputation: 190

There are two points that you have to check

. Is your view( viewForautoCompleteTableView) allocated ?

. If you want to change the width while rotation then you have to change the width of your view in didRotateFromInterfaceOrientation:UIInterfaceOrientation)fromInterfaceOrientation method

-(void)didRotateFromInterfaceOrientation:    (UIInterfaceOrientation)fromInterfaceOrientation{

// put the condition to check for your orientation type i.e. portrait or landscape

CGSize newSize= CGSizeMake(newWidth,height); // setting new width here
CGRect viewFrame=viewForautoCompleteTableView.frame;
 viewFrame. size  = newSize;
 viewForautoCompleteTableView.frame=textFrame; // provide some animation if required 

}

Note:- Please make sure your view is allocated

Upvotes: 0

Bhavin
Bhavin

Reputation: 27235

Note that : On Rotation, self.view.frame size does not change but self.view.bounds does , and bounds represent correct values with respect to current Interface Orientation.

Upvotes: 1

Related Questions