Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the position of a Form Sheet Modal View Controller

How would one change the position of a Form Sheet Modal View Controller?

By default it is positioned in the centre of the screen, I would like to offset the Form Sheet position so that when I display the keyboard it does not overlap the Form Sheet window.

Is this possible?

like image 802
Dan Avatar asked Oct 03 '11 23:10

Dan


2 Answers

You can modify the frame of the parent controller. something like:

CGRect frame = self.parentViewController.view.frame;
frame.origin.x -= 50;
frame.origin.y -= 50;
self.parentViewController.view.frame = frame;

this will move the position of your modal view by (-50,-50)

like image 136
jyavenard Avatar answered Nov 16 '22 14:11

jyavenard


If you're using a UIViewController and presenting it using presentModalViewController, then you have to accept the default behavior for the type you've specified (form). That's going to land square in the center every time. So the way you're doing it, it isn't possible.

However, it'd be relatively trivial to create your own view and present it yourself by animating it in and out (and performing some work to darken/disable interaction on views situated below), giving you the power to place it wherever you want.

As far as accommodating the keyboard, I suppose I'd consider scrolling the subview you're presenting in the form view to the appropriate offset.

Hope this is helpful.

like image 20
isaac Avatar answered Nov 16 '22 15:11

isaac