PresentModalViewController with some frame

牧云@^-^@ 提交于 2019-12-23 03:51:24

问题


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?


回答1:


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).




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/11230159/presentmodalviewcontroller-with-some-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!