Bharath
Bharath

Reputation: 3031

PresentModalViewController with some frame

I want to present a modalViewController with a small frame and at the center of the view.

Is that possible?

Even if I set some frame to the viewController object, presentModelViewController is displaying that view in full screen mode.

Also, I have used modalPresentationStyle as UIModalPresentationFormSheet. I want to have frame even smaller than that.

How to do that?

Upvotes: 1

Views: 2279

Answers (3)

ABC1
ABC1

Reputation: 116

Yes. It is possible. Please follow below steps:

- (void)viewDidLoad {
     [super viewDidLoad];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShown:) name:UIKeyboardWillShowNotification object:nil];
     CGRect rect = CGRectMake(242, 60, 540, 312);
     self.controller.view.superview.frame = [self.view convertRect:rect toView:self.controller.view.superview.superview];
}

- (void)keyboardWillShown:(NSNotification*)aNotification {
     CGRect rect = CGRectMake(242, 60, 540, 312);
     self.controller.view.superview.frame = [self.view convertRect:rect toView:self.controller.view.superview.superview];
}

You have to set frame of present controller after your controller setting (just before viewDidLoad method end).

Here I have considered iPad present view controller frame.

Upvotes: 0

crackity_jones
crackity_jones

Reputation: 1077

Presenting a modal view will cover the entire view, if you don't wish to cover the entire view then you should create the view yourself, add it to the current view as a subView and then animate its transition yourself. It would not be a separate viewController because you're still operating within the bounds of the original view.

Upvotes: 1

Nitin Alabur
Nitin Alabur

Reputation: 5812

You cannot present a modal view controller that has a smaller frame size.

what you can try doing is to set the background of your modal view controller to transparent and then add the smaller sized view in the center (or where ever you wish to have it seen).

Upvotes: 5

Related Questions