tags:

views:

65

answers:

2

I have a view controller and I am presenting it modal, as in...

UIViewController *myWindow = [[UIViewController alloc] init];
CGRect myFrame = CGRectMake(0.0f, 0.0f, 115.0f, 120.0f);
myWindow.view.frame = myFrame;

[self presentModalViewController:myWindow animated:YES];

is there any way I can present it not full screen in a specific size?

+1  A: 

There is no 'standard' way to do this.

I have faked it by using a UIActionSheet and setting the view controller's view to as a subview of the actionsheet, and then resetting the bounds of the actionsheet. This is a pretty odd hack and I wouldn't recommend it.

sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
sheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;

UIViewController *modalController = [[UIViewController alloc] initWithNibName:@"SomeNib" bundle:nil];

sheet.autoresizesSubviews = NO;
[sheet addSubview:modalController.view];
[sheet showInView:self.view];
[UIView beginAnimations:nil context:nil];
[sheet setBounds:CGRectMake(0, 0, 320, 728)];
[UIView commitAnimations];

The obvious drawbacks here are the normal view controller events aren't triggered (viewWillAppear:, viewDidAppear:, etc)

Joshua Weinberg
thanks. I think I will use it fullscreen anyway... :)
Digital Robot
+2  A: 

Not easily but you can make it seem smaller :)

Just make the root IUView in your xib full screen but with a clear transparent background. Then, inside that make your 'real' UI objects any size you want.

deanWombourne
From what I've seen, when the modal presentation is completed, the view behind is unloaded, causing it to go black
Joshua Weinberg
Ah yes, it might do that. Blast. Oh well, looks like your way is the only way!
deanWombourne