-1

I am using this code to load a view when I touch a button in Xcode.

UIStoryboard *storyboard = self.storyboard;
UIViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"FirstCar"];[self presentViewController:svc animated:YES completion:nil];

The view loads from the bottom, which I wish it didn't but loaded from the side instead. The main problem is that when it finish loading there is a gap at the top of about 1/2 inch. I have used this code to load it above the top depending screen size.

backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(-20, -20, 454, 776)];

It used to work ok but now for some reason it doesn't. And when I top/hold on an object to move it using "DragView", the object moves jerkily but the whole view moves up and down. I can even make the views contents completely disappear by swiping down. It doesn't go the the previous view just totally blank black. I don't know if that is related but something is weird. Does anyone have any ideas what I am doing wrong. Thanks in advance.

user1114881
  • 727
  • 1
  • 12
  • 23

1 Answers1

0

What you are describing is the default behavior of a presented view controller in iOS 13 - presented VCs slide in from the bottom and leave a gap at the top (indicating that the user can dismiss by dragging down).

You can remove the gap (and swipedown behavior) by setting the presented VC's modalPresentationStyle to fullscreen like this:

svc.modalPresentationStyle = UIModalPresentationFullScreen;

Add that line before calling present (or you can set that value in your storyboard) and you should see it cover the screen. You can find documentation of other presentation styles in the Apple docs

As for the right-to-left animation you mentioned, a sideways slide in is usually associated with UINavigation controller pushes rather than modal presentations, but as mentioned in this post, you can achieve the sideways animation on a modal using a custom transition.

Here's the relevant code in that post:

CATransition *transition = [[CATransition alloc] init];
transition.duration = 0.5;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.view.window.layer addAnimation:transition forKey:kCATransition];
[self presentViewController:svc animated:false completion:nil];
BevTheDev
  • 557
  • 2
  • 9