本次实现的效果如图1:
图1首先我们自定义一个Pop控制器WJLPopViewController;
首先实现核心部分当点击按钮加的时候回弹出下拉菜单的一个效果。
1.指定当前控制器的modalPresentationStyle为UIModalPresentationPopover。注:这部必须做,不然后面的popoverPresentationController无效。
2.设置当前控制器的popoverPresentationController。
1>self.popoverPresentationController.barButtonItem = item;//弹出的位置
还可以通过sourceView和sourceRect来指定.具体见后面代码
2>self.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;//箭头方向,这里朝上
3>self.popoverPresentationController.delegate =self;//设置代理并在代理方法返回UIModalPresentationNone。//其他style都不行。
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
return UIModalPresentationNone;
}
二.为了让菜单有个tab的效果在控制器中加入tableView.
在WJLPopViewController.h中设置相应协议,方便通过点击tab上的cell回调具体点击的位置。
完整代码地址: 下载地址
网友评论