需求:iPad里,要求popup一个login window,该window的size是小的,不要遮住整个iPad当前显示的view。
我尝试使用下列代码 (其中LoginViewController是loginview with full iPad screen size,其中中间部分设置成蓝色,而周边部分设置成透明色,造成在popup之后周边部分不遮住当前显示view。
FormStyleViewController* form=[[FormStyleViewController alloc]initWithNibName:@“LoginViewController"bundle:nil];
//support modal view clear background
self.modalPresentationStyle= UIModalPresentationCurrentContext;
[self presentViewController:formanimated:YEScompletion:nil];
对于上面代码,如果删除
self.modalPresentationStyle= UIModalPresentationCurrentContext;
那么周边背景就会变黑色
如果添加
form.modalPresentationStyle = UIModalPresentationFormSheet;
那么就会以form style view来显示,虽然整个view size变小了,但导致周边背景色变成灰色而不是透明。
不过上述代码导致了一个问题,就是如果旋转iPad,popup window会旋转,但parent view则不会旋转。但如果以formstyle view来显示,则parent view也会旋转。这个issue解决不了,虽然这个链接提供了方法,但我在ios7里运行时画面会变黑。所以使用UIModalPresentationCurrentContext并不是解决方案,除非你的app不能旋转
因此,如果你要在ipad里的当前fullscreen view上弹出一个小窗口的话,你有如下选择:
1. 使用popover
2. 使用modalPresentationStyle。但要注意,modalPresentationStyle的bg color无法是透明的,所以你必须用尽整个view screen
3. 不使用小窗口,而使用modal view with full screen