Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does presentViewController change view.frame?

Tags:

objective-c

I hava a question about screen transition.

To transit a screen, I often use presentViewController method.

NextViewController *nextViewController = [[NextViewController alloc] init];
nextViewController.view.frame = CGRectMake(10, 10, 200, 400);    
[self presentViewController:nextViewController animated:YES completion:nil];

However, the view.frame setting that I implemented is not applied.

Following code runs correctly.

NextViewController *nextViewController = [[NextViewController alloc] init];
[self presentViewController:nextViewController animated:YES completion:nil];
nextViewController.view.frame = CGRectMake(10, 10, 200, 400);

What's the difference of these code? Is view.frame redefined in presentViewController method?

Thanks.

like image 796
akiniwa Avatar asked Dec 19 '12 06:12

akiniwa


1 Answers

NextViewController *nextViewController = [[NextViewController alloc] init];
nextViewController.view.frame = CGRectMake(10, 10, 200, 400);    
[self presentViewController:nextViewController animated:YES completion:nil];

The above code is not working because you are setting the view of nextViewController which not yet created.

so in your next code you load the view controller first and then change the frame of the loaded view.

=========================EDIT===========================

If you want to set the frame in the view controller directly then bind your view with a IBOutlet and then in

- (void) viewDidAppear:(BOOL)animated
 {
      //set the frame here
      self.myView.frame = CGRectMake(10, 10, 200, 400);
 }

Hope it helps :)

like image 185
Ajeet Pratap Maurya Avatar answered Nov 26 '22 09:11

Ajeet Pratap Maurya