iOS: Present modal view with smaller size in iPad

在ipad里,想popup一个login modal window,该window要小过ipad size。怎么做?


by default,present a modal view是以full screen来popup。其实有几个presentation style:(ref link)

UIModalPresentationFullScreen   default style

UIModalPresentationFormSheet  会将窗口缩小,使之居于屏幕中间,在portrait和landscape下都一样,但要注意landscape下如果软键盘出现,窗口位置会调整

UIModalPresentationPageSheet 在portrait时是FullScreen,在 landscape时和FormSheet模式有点像(上下没有留出空间),注意有这种需求的朋友直接用这种模式就可以了,不要想着自己编程去在 FullScreen和FormSheet去切换,很麻烦

UIModalPresentationCurrentContext使modal view显示半透明

Here 可以看到UIModalPresentationFormSheet 和UIModalPresentationPageSheet  的效果


那么要满足我们之前的要求,可以使用UIModalPresentationFormSheet.  

Example

myModalView.modalPresentationStyle = UIModalPresentationFormSheet;

[self presentModalViewController:myModalView animated:YES];


不过UIModalPresentationFormSheet显示的窗口by default是无法修改大小的,要修改大小参看http://stackoverflow.com/questions/2457947/how-to-resize-a-uipresentationformsheet, 注意要考虑rotate的情况,如果没有考虑的话,rotate to landscape不会居中!!


另外还有一个办法就是使用UIModalPresentationCurrentContext 的半透明效果。但是使用这个style在旋转后会modal view旋转,但parent没有旋转 :(


popovercontroller应该也可以实现该效果


小技巧

创建带xib的class所生成的xib的view的size无法修改,你可以在该view的属性窗口的"Simulated Metrics > Size"属性(注意只是模拟,而不是真的size)里把其改为FreeForm

该"Size"属性还有其他一些值 (Master, Detail, iPad Full Screen, Page sheet, Form sheet):不同的值对应一个fix size。



你可能感兴趣的:(iOS: Present modal view with smaller size in iPad)