- PopMenu在iOS开发中很常见的,第三方的也很多,写起来也不难。一般是自己自定义个View,然后放到window上。其实从UIAlertView到UIAlertController可以看出,苹果不建议把东西放到window上,应该用UIViewController来管理。
- 自己写这个。1、没找到合适的第三方的,尝试用UIViewController重新写。2、自己也尝试下发布到Cocoapods的过程。
- 写的过程中 参考了 PopMenuTableView和PopMenu。
- PopMenuTableView就是自定义的view然后放到widow上,然后有点不喜欢它用类方法来处理的思路。
- PopMenu 是个国外写的很优秀的swift框架,动画效果也很不错,但是国内的APP好像很少这种样式。
效果图如下

安装
- 使用
cocoapods
Podfile
文件中添加pod 'ZLPopMenuViewController'
- 也可以直接把代码拖到工程中
使用
swift
- 在
viewControll
中添加import ZLPopMenuViewController
let datas1: [ZLPopMenuModel] = [.init(itemName: "首页(4)"),
.init(itemName: "首页"),
.init(itemName: "确认")]
let popVC = ZLPopMenuViewController.init(sourceView: sender, menuData: datas1)
popVC.didClickItems = {(index, model)in
}
present(popVC, animated: true, completion: nil)
Objective-C
- 在
viewControll中
添加#import <ZLPopMenuViewController/ZLPopMenuViewController-Swift.h>
ZLPopMenuModel *model = [[ZLPopMenuModel alloc]initWithItemName:@"菜单" imageName:nil];
ZLPopMenuViewController *popVC =[[ZLPopMenuViewController alloc] initWithSourceView:testView
menuData:@[model, model, model]
menuStyle:ZLPopMenuStyleWhite
popMenuConfig:[ZLPopMenuConfig default]];
[self presentViewController:popVC animated:true completion:nil];
[popVC setDidClickItems:^(NSInteger indx, ZLPopMenuModel * _Nonnull model) {
NSLog(@"OC中点击了 %ld, %@", indx, model);
}];
最后放上地址ZLPopMenuViewController,也欢迎大家随意改样式。
网友评论