Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone - can presentModalViewController do it not fullscreen?

Tags:

iphone

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?

like image 894
Duck Avatar asked Mar 02 '26 16:03

Duck


1 Answers

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)

like image 140
Joshua Weinberg Avatar answered Mar 05 '26 07:03

Joshua Weinberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!