PresentModalViewController shifts the new view too far and goes above the top of the screen

-(void)reviewClicked:(id)sender { ReviewViewController *newView = [[ReviewViewController alloc] init]; newView.delegate = self; UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:newView]; [self presentModalViewController:navCon animated:YES]; } 

I have a splitViewController setting, which is probably causing some problems. Inside the detailed view controller, I have a button that, when clicked, calls the above code.

The goal is to shift the view from bottom to top so that the user can view their selection, and then click the button to return to the original detailed view. This code works, and you can click forward and backward between the modal view and the original detail view.

The problem is that after it slides across the screen, it continues to slide when it should stop, and finally stops the good 10-15 pixels too far. Basically, this modal view glides so far that a good portion of the presentation goes beyond the top of the screen. Meanwhile, the same space of space is the “empty black space” at the bottom of the screen, which once again indicates that the view is simply too moved upward.

Complicating matters, he slides in fine mode in landscape mode.

So the question is, does anyone know why this error occurs in order to make the modal view slide too far up and at the top of the screen?

- = - = - = - = - = - = -

Edit: Sorry, I intended to type navCon at this location. I fixed it above.

- = - = - = - = - = - = -

Decision:

 -(void)reviewClicked:(id)sender { ReviewViewController *newView = [[ReviewViewController alloc] init]; newView.delegate = self; UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:newView]; navCon.view.frame = CGRectMake(0, 0, 768, 1080); [self presentModalViewController:navCon animated:YES]; } 

After some trial and error, I realized that I never set the view frame! The solution is as simple as ... I used examples containing .xib files, and since these files automatically created the frame, I completely ignored it!

Keep in mind for those who are looking at this in the future. This frame is for portrait mode only. If you want landscape mode, just change the frame accordingly:

 navCon.view.frame = CGRectMake(0, 0, 1080, 768); 
0
source share
1 answer

Although I found a quick solution to the problem as described in the question. The fact is that there were a lot of problems around. After further inspection, I called appDelegate to call these methods:

 [self.splitViewController presentModalViewController:navCon animated:YES]; [self.splitViewController dismissModalViewControllerAnimated:YES]; 

Basically, I had a root view class calling a modal view that solved ALL my problems. Apparently, calling a modal view from a detailed view of splitview is NOT the same as calling a modal view from the root view (which turned out to be a splitViewController). Hope this helps anyone in the future. Greetings.

- = - = - = - = - = - = - = -

For more information, see this post I came across:

UISplitViewController - Clicking a modal view

0
source

Source: https://habr.com/ru/post/1315345/


All Articles