iOS: Present modal view with smaller size in iPad

本文介绍了如何在iPad上通过iOS SDK调整模态窗口的大小,采用UIModalPresentationFormSheet样式实现自定义大小的登录模态窗口,并提供了实例代码演示,同时讨论了旋转情况下的窗口定位问题。

在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。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值