关于UIPopverController的几点注意

1、UIPopoverController不能定义为局部变量,必须是类属性或成员变量,要保证它的作用域是整个对象范围内。


2、对于UIPopoverController的显示大小,官方文档有如下解释

The popover normally derives its initial size from the contentSizeForViewInPopover property of the view controller being presented. The default size stored in this property is 320 pixels wide by 1100 pixels high. You can customize the default value by assigning a new value to thecontentSizeForViewInPopover property. Alternatively, you can assign a value to the popoverContentSize property of the popover controller itself. If you change the view controller displayed by a popover, any custom size information you put in the popoverContentSize property is replaced by the size of the new view controller. Changes to the content view controller or its size while the popover is visible are automatically animated. You can also change the size (with or without animations) using the setPopoverContentSize:animated: method.

大意如此:UIPopoverController通常会按照当前的那个contentViewController的contentsizeforviewinpopover属性来初始化它的大小。contentsizeforviewinpopover默认的大小是宽度320,高度1100(不太理解???)。

当然你也可以赋值给popover自身的popovercontentsize属性。但是!!!如果你popover里面做控制器跳转,不管你给popovercontentsize赋了值什么值,都会被新的控制器的size替代。

所以记得这个时候一定要在新的控制器的viewWillAppear里面使用contentsizeforviewinpopover属性设置控制器的大小,否则默认大小为宽320,高度好像是系统自己调节的。

contentsizeforviewinpopover这个属性到了ios7就被弃用了,用preferredContensize代替。


3、文档中有个地方有说同一个时刻只能显示一个popover,所以示例代码中popoverVisible属性先检查popover是否已经显示了,不过我去掉后也没发现什么问题。


4、popoverBackgroundViewClass属性是UIPopverController的背景:包括整个背景框和箭头,箭头和背景框是分开的,箭头可以根据传入的锚点和方向做变化。可以通过继承这个类来自定义popover的背景样式。


5、在设备旋转的时候,如果有显示popover,就得在旋转前记下是哪个button,dismiss popover。然后在旋转后的回调方法中根据那个button的frame重新present popover。


6、使用UIPopoverController的几个建议
(1)取消popover的显示要用到指向popover的指针,一般将popover的指针保存在它的内容控制器中,这样就可以在响应用户操作的时候让popover消失。
(2)在视图控制器中最好重用一个popover变量,popover本身有很好的延展性,你可以给它指定不同的内容视图控制器。
(3)无论什么时候,都要给popover指定箭头方向,如果你指定的箭头方向是一个集合,popover可能会缩小。


转载请注明出处:博客:疾风知草劲  作者:away

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值