弹出菜单 — UIPopoverPresentationController

今天实现一个小功能, 仿微信、QQ 那样的弹出菜单.

在之前如果想要在iphone上实现popover的效果需要自定义view,在iOS8中提供了UIPopoverPresentationController在ipad和iphone两个设备上同时实现popover的效果。

UIPopoverPresentationController是UIViewController的一个属性,所以并不需要你特地去建立一个UIPopoverPresentationController来进行操作,而应该建立一个UIViewController。

一、首先看效果图:


弹出菜单 — UIPopoverPresentationController_第1张图片
弹出菜单 — PopoverView

二、实现思路:

1.  弹出视图控制器是控制器本身自带的一个属性,所以在用的时候不需要实力化。弹出视图控制器需要两个控制器,一个用来触发弹出控制器事件。一个用来做弹出控制器

创建一个新的 视图控制器 -- PopViewController

创建 弹出视图要展示的内容数组; 同时 创建UITbaleView, 并设置好协议方法 (如图)

弹出菜单 — UIPopoverPresentationController_第2张图片
创建一个新的 视图控制器 -- PopViewController

2.现在, 弹出视图的内容已经设置好了, 剩下的就是设置视图的弹出方式,

弹出菜单 — UIPopoverPresentationController_第3张图片
弹出菜单 — UIPopoverPresentationController_第4张图片
在弹出视图的响应事件的方法中, 设置弹出的菜单

源码下载

如果这篇文章对您有些许帮助 请给我点个心哦。


你可能感兴趣的:(弹出菜单 — UIPopoverPresentationController)