博客
关于我
KxMenu下拉菜单
阅读量:802 次
发布时间:2023-01-29

本文共 4512 字,大约阅读时间需要 15 分钟。

###.iOS 7 下创建动态菜单](#cnblogs_post_body)

在 .iOS 7 下,创建动态菜单是一个常见的任务。以下代码实现了动态菜单的创建逻辑,适用于 .iOS 7 及以上版本。

+ (void)createMenu:(id)sender target:(UIViewController *)t{    NSArray *menuItems =     @[        [KxMenuItem menuItem:@"发送给朋友" image:[UIImage imageNamed:@"menu_weixin"] target:t action:@selector(shareToFriend)],        [KxMenuItem menuItem:@"分享到朋友圈" image:[UIImage imageNamed:@"menu_weixin_circle"] target:t action:@selector(shareToCircle)],        [KxMenuItem menuItem:@"随手摇一摇" image:[UIImage imageNamed:@"menu_shake"] target:t action:@selector(shakeAndShake)],        [KxMenuItem menuItem:@"检查更新" image:[UIImage imageNamed:@"menu_checkupdate"] target:t action:@selector(checkUpdate)],        [KxMenuItem menuItem:@"意见反馈" image:[UIImage imageNamed:@"menu_feedback"] target: t action:@selector(initFeedBack)],        [KxMenuItem menuItem:@"关于闪酷" image:[UIImage imageNamed:@"menu_about"] target:t action:@selector(aboutShanku)],    ];        if (IS_IOS7)    {        menuItems =         @[            [KxMenuItem menuItem:@"发送给朋友" image:[UIImage imageNamed:@"menu_weixin"] target:t action:@selector(shareToFriend)],            [KxMenuItem menuItem:@"分享到朋友圈" image:[UIImage imageNamed:@"menu_weixin_circle"] target:t action:@selector(shareToCircle)],            [KxMenuItem menuItem:@"随手摇一摇" image:[UIImage imageNamed:@"menu_shake"] target:t action:@selector(shakeAndShake)],            [KxMenuItem menuItem:@"随手扫一扫" image:[UIImage imageNamed:@"menu_qrcode"] target:t action:@selector(scanAndScan)],            [KxMenuItem menuItem:@"检查更新" image:[UIImage imageNamed:@"menu_checkupdate"] target:t action:@selector(checkUpdate)],            [KxMenuItem menuItem:@"意见反馈" image:[UIImage imageNamed:@"menu_feedback"] target: t action:@selector(initFeedBack)],            [KxMenuItem menuItem:@"关于闪酷" image:[UIImage imageNamed:@"menu_about"] target:t action:@selector(aboutShanku)],        ];    }        UIView *targetView = (UIView *)[sender performSelector:@selector(view)];    CGRect _rect = targetView.frame;    _rect.origin.y = _rect.origin.y + 30;    CGRect rect = _rect;        [KxMenu showMenuInView: t.navigationController.view fromRect: rect menuItems:menuItems];}

[代码块结束]


shakeToShake 通知处理

当应用程序接收到 shakeToShake 通知时,会触发以下逻辑:

+ (void) shakeToShake: (NSNotification *) notification{    NSDictionary *info = [notification userInfo];    SKShakeViewController *shakeView = [[SKShakeViewController alloc] init];        [[info objectForKey:@"controller"] pushViewController:shakeView animated:YES];}

[代码块结束]


scanAndScan 函数

+ (void) scanAndScan: (NSNotification *) notification{    [self setupCamera: notification];}

[代码块结束]


setupCamera 函数

+ (void) setupCamera: (NSNotification *) notification{    NSDictionary *info = [notification userInfo];        if (IS_IOS7)    {        SKScanViewController *scan = [[SKScanViewController alloc] init];        [[info objectForKey:@"controller"] presentViewController:scan animated:YES completion:^{ }]; // void块            }    else    {        // 为非.iOS 7 版本留空或根据需求实现其他逻辑    }}

[代码块结束]


分享到朋友圈

+ (void) shareToFriendCircle{    SKAppDelegate *AppDelegate = (SKAppDelegate *)[[UIApplication sharedApplication] delegate];    [AppDelegate changeScene:WXSceneTimeline];    [AppDelegate sendLinkContent];        [MobClick event:@"shareToCircle"];}

[代码块结束]


分享到朋友

+ (void) shareToFriend{    SKAppDelegate *AppDelegate = (SKAppDelegate *)[[UIApplication sharedApplication] delegate];    [AppDelegate changeScene:WXSceneSession];    [AppDelegate sendLinkContent];        [MobClick event:@"shareToFriend"];}

[代码块结束]


关于页面

+ (void) aboutShanku: (NSNotification *) notification{    NSDictionary *info = [notification userInfo];    SKAboutViewController *about = [[SKAboutViewController alloc] init];    [[info objectForKey:@"controller"] pushViewController:about animated:YES];}

[代码块结束]


检查更新

+ (void) checkUpdate{    [MobClick checkUpdateWithDelegate:self selector:@selector(isUpdate:)];}+ (void)isUpdate:(NSDictionary *)appInfo{    if ([[appInfo objectForKey:@"update"] isEqualToString:@"NO"])    {        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"已经是最新版本" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];        [alertView show];    }}

[代码块结束]


获取版本号

+ (NSString *) getBundleVersion{    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];    return version;}

[代码块结束]


以上代码为您提供了一个完整的菜单创建和功能扩展逻辑,适用于 .iOS 7 及以上版本。代码结构清晰,易于维护和扩展。


转载请注明:https://www.cnblogs.com/songxing10000/p/4823651.html

你可能感兴趣的文章
Openlayers中加载Geoserver切割的EPSG:900913离线瓦片图层组
查看>>
Openlayers中多图层遮挡时调整图层上下顺序
查看>>
Openlayers中将某个feature置于最上层
查看>>
Openlayers中点击地图获取坐标并输出
查看>>
Openlayers中设置定时绘制和清理直线图层
查看>>
Openlayers图文版实战,vue项目从0到1做基础配置
查看>>
Openlayers实战:modifystart、modifyend互动示例
查看>>
Openlayers实战:判断共享单车是否在电子围栏内
查看>>
Openlayers实战:加载Bing地图
查看>>
Openlayers实战:绘制图形,导出geojson文件
查看>>
Openlayers实战:绘制图形,导出KML文件
查看>>
Openlayers实战:绘制多边形,导出CSV文件
查看>>
Openlayers实战:绘制带箭头的线
查看>>
Openlayers实战:输入WKT数据,输出GML、Polyline、GeoJSON格式数据
查看>>
Openlayers实战:非4326,3857的投影
查看>>
Openlayers高级交互(10/20):绘制矩形,截取对应部分的地图并保存
查看>>
Openlayers高级交互(11/20):显示带箭头的线段轨迹,箭头居中
查看>>
Openlayers高级交互(14/20):汽车移动轨迹动画(开始、暂停、结束)
查看>>
Openlayers高级交互(15/20):显示海量多边形,10ms加载完成
查看>>
Openlayers高级交互(16/20):两个多边形的交集、差集、并集处理
查看>>