8

Quick question again. When I use presentViewController to present a new viewcontroller on top of my current one it is full screen. How do I get it to present a specific size? Or should I use another method.

Code:

- (IBAction)showProfile:(id)sender {
ProfileView *profileTop = [[ProfileView alloc] init];
profileTop.delegate = self;

[self presentViewController:profileTop animated:YES completion:nil];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Tarayaa
  • 127
  • 1
  • 1
  • 8

4 Answers4

10

If you are developing an app for iPad then you can make use of viewController's modalPresentationStyle property, You need to set for presenting viewController.

It has 4 values for that variable.

UIModalPresentationFullScreen = 0,
UIModalPresentationPageSheet,
UIModalPresentationFormSheet,
UIModalPresentationCurrentContext

You can select which one suites you the best.

Prasad Devadiga
  • 2,573
  • 20
  • 43
  • I did read about this but I had no idea how to implement it..can you elaborate on your code? – Tarayaa May 23 '13 at 07:59
  • 1
    Sure, Please add this line `profileTop.modalPresentationStyle = UIModalPresentationFormSheet;` before presenting to make the ProfileView aligned to center. – Prasad Devadiga May 23 '13 at 08:52
  • This is not exactly what I was going for..but it's actually a really smooth animation. I guess im gonna have to read up on the UIModalPresentations – Tarayaa May 23 '13 at 09:05
  • I actually think im gonna use this instead of the idea I had, thanks! How would you remove the field when tapping outside of it? – Tarayaa May 23 '13 at 09:08
  • If you want to achieve nice animation you can make use of `modalTransitionStyle` try this also, its really cool :) – Prasad Devadiga May 23 '13 at 09:14
  • May be you can try this link for dismiss, http://stackoverflow.com/questions/2623417/iphone-sdk-dismissing-modal-viewcontrollers-on-ipad-by-clicking-outside-of-it I have not tried it. – Prasad Devadiga May 23 '13 at 09:20
  • What a coincidence I was just reading that link haha. Did not figure it out yet but can't be that hard, thanks! – Tarayaa May 23 '13 at 09:26
  • I did this but the modalvc presented is still full screen for some reason. – marciokoko Dec 23 '13 at 17:46
7

I'd suggest doing a little more research, specifically in Apple's reference. Of note, there is this quote from the View Controller Programming Guide (http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html):

Presentation Styles for Modal Views

For iPad apps, you can present content using several different styles. In iPhone apps, presented views always cover the visible portion of the window, but when running on an iPad, view controllers use the value in their modalPresentationStyle property to determine their appearance when presented. Different options for this property allow you to present the view controller so that it fills all or only part of the screen.

And specifically, on the API reference page for presentViewController (http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/presentViewController:animated:completion:):

On iPhone and iPod touch, the presented view is always full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.

Only the iPad appears to have any support for non-fullscreen modals.

Jason M. Batchelor
  • 2,951
  • 16
  • 25
4

On iPad you can just use:

[viewcontroller setModalPresentationStyle:UIModalPresentationFormSheet];

example:

LoginDialogViewController * login_dialog = [[LoginDialogViewController alloc] init];
[login_dialog setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentViewController:login_dialog animated:true completion:nil];
pkamb
  • 33,281
  • 23
  • 160
  • 191
Notive
  • 51
  • 1
0

You can use the same code. Then adjust the view size in the xib file. See the below figure size inspector

Nikhila Mohan
  • 2,000
  • 2
  • 15
  • 19