对于UIPopoverController的解读(上)

        

UIPopoverController类用于管理内容呈现在popover(弹出框)。使用popovers暂时呈现信息。该popover内容分层显示在现有内容的上方和背景自动变暗,直到用户点击popover窗口的之外的地方或是明确移除popoverPopover控制器是专门使用在iPad设备上,如果你试图在一个不是ipad的设备上创建一个popover的话,程序会报异常。

  为了显示一个popover,你需要为这个类创建一个实例对象并用适当的方法展示它。当初始化这个类的时候,你必须为popover指定提供内容的视图控制器。Popovers通常是从他们目前的视图控制器中获得它们的大小。不过,你也可以通过改popoverContentSize属性或者调用setPopoverContentSize:animated:方法来改变popover的大小。如果你想动态改变popover的大小的话,后面一种方法是比较好的。你指定的大小对于popover来说是首选的。为了确保popover适配在屏幕上并且不与键盘冲突,其实际尺寸是可以改变的。

为了让用户使用指定的视图进行交互,而不去隐藏popover,你可以使用passthroughViews属性来指定多个视图。当点击popover内部视图的时候不会造成popover自动消失。而如果需要让popover消失的话,你的视图和视图控制器必须处理popover内的行为和事件,并要调用dismissPopoverAnimated:方法。

如果用户旋转设备时popover是可见的,当设备旋转时popover控制器会隐藏popover,然后在旋转结束后再次显示它。popover视图控制器会尝试自动适当地为你显示位置,但是你也可以通过实现popoverController:willRepositionPopoverToRect:inView:代理方法来明确设置一个新的位置。

你可以为popover指定一个委托,来管理与popover的交互并接收popover消失时的通知。如果你想进一步了解popover的代理对象可以查看UIPopoverControllerDelegate Protocol Reference.


参考官方文档:

TheUIPopoverController class is used to manage the presentation of content in a popover. You use popovers to present information temporarily. The popover content is layered on top of your existing content and the background is dimmed automatically. The popover remains visible until the user taps outside of the popover window or you explicitly dismiss it. Popover controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception.

To display a popover, create an instance of this class and present it using one of the appropriate methods. When initializing an instance of this class, you must specify the view controller that provides the content for the popover. Popovers normally derive their size from the view controller they present. However, you can change the size of the popover by modifying the value in thepopoverContentSize property or by calling thesetPopoverContentSize:animated: method. The latter approach is particularly effective if you need to animate changes to the popover’s size. The size you specify is just the preferred size for the popover’s view. The actual size may be altered to ensure that the popover fits on the screen and does not collide with the keyboard.

When displayed, taps outside of the popover window cause the popover to be dismissed automatically. To allow the user to interact with the specified views and not dismiss the popover, you can assign one or more views to the passthroughViews property. Taps inside the popover window do not automatically cause the popover to be dismissed. Your view and view controller code must handle actions and events inside the popover explicitly and call the dismissPopoverAnimated: method as needed.

If the user rotates the device while a popover is visible, the popover controller hides the popover and then shows it again at the end of the rotation. The popover controller attempts to position the popover appropriately for you but you can also implement the popoverController:willRepositionPopoverToRect:inView: method in the popover delegate to specify a new position.

You can assign a delegate to the popover to manage interactions with the popover and receive notifications about its dismissal. For information about the methods of the delegate object, see UIPopoverControllerDelegate Protocol Reference.


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值