iOS 3Dtouch 开发
2016-02-16 00:00
471 查看
摘要: UIApplicationShortcutItems,peek,pop,peek上拉菜单
先附上Demo:https://git.oschina.net/1203556555/JY3DtouchDemo.git
转载请注明出处
UIApplicationShortcutItems即用3Dtouch在app图标呼出一个菜单
实现由两种方法:静态菜单和动态菜单
静态菜单是在plist中添加,优点是在第一次打开app前就生效
动态菜单是用代码生成,缺点是在第一次打开app前无法生效故不做演示
实现点击菜单直接打开指定控制器
2.peek和pop
//实现peek和pop手势:
//1、遵守协议 UIViewControllerPreviewingDelegate
//2、注册 [self registerForPreviewingWithDelegate:self sourceView:self.view];
//3、实现代理方法
遵守协议
//peek,pop相关属性
注册
实现peek,pop方法
实现peek上拉菜单
//在peek打开的控制器里遵守协议
//设置菜单项
先附上Demo:https://git.oschina.net/1203556555/JY3DtouchDemo.git
转载请注明出处
UIApplicationShortcutItems即用3Dtouch在app图标呼出一个菜单
实现由两种方法:静态菜单和动态菜单
静态菜单是在plist中添加,优点是在第一次打开app前就生效
动态菜单是用代码生成,缺点是在第一次打开app前无法生效故不做演示
实现点击菜单直接打开指定控制器
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler { if ([shortcutItem.localizedTitle isEqualToString:@"我的二维码"]) { //跳转到第一个tabbar self.rootTabbarCtr.selectedIndex = 0; JYTwoDimensionCodeViewController *vc = [[JYTwoDimensionCodeViewController alloc]init]; vc.hidesBottomBarWhenPushed = YES; [self.homeViewController.navigationController pushViewController:vc animated:NO]; } else if([shortcutItem.localizedTitle isEqualToString:@"扫一扫"]){ //跳转到第一个tabbar self.rootTabbarCtr.selectedIndex = 0; JYScanViewController *vc = [[JYScanViewController alloc]init]; vc.hidesBottomBarWhenPushed = YES; [self.homeViewController.navigationController pushViewController:vc animated:NO]; } }
2.peek和pop
//实现peek和pop手势:
//1、遵守协议 UIViewControllerPreviewingDelegate
//2、注册 [self registerForPreviewingWithDelegate:self sourceView:self.view];
//3、实现代理方法
遵守协议
@interface JYMoreViewController ()<UITableViewDelegate,UITableViewDataSource,UIViewControllerPreviewingDelegate>
//peek,pop相关属性
@property (nonatomic, assign) CGRect sourceRect; @property (nonatomic, strong) NSIndexPath *selectedPath;
注册
- (void)viewDidLoad { [super viewDidLoad]; //注册pop,peek方法 [self registerForPreviewingWithDelegate:self sourceView:self.view]; }
实现peek,pop方法
//peek手势 - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint) location { // 获取用户手势点所在cell的下标。同时判断手势点是否超出tableView响应范围。 if (![self getShouldShowRectAndIndexPathWithLocation:location]) return nil; //弹出视图的初始位置,sourceRect是peek触发时的高亮区域。这个区域内的View会高亮显示,其余的会模糊掉 previewingContext.sourceRect = self.sourceRect; UIViewController *childVC = [[JYPopViewController alloc] init]; return childVC; } //pop手势 - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit { viewControllerToCommit.hidesBottomBarWhenPushed = YES; // [self tableView:self.moreTableView didSelectRowAtIndexPath:self.selectedPath]; [self showViewController:viewControllerToCommit sender:nil]; } //获取用户手势点所在cell的下标,同时判断手势点是否超出tableview的范围 - (BOOL)getShouldShowRectAndIndexPathWithLocation:(CGPoint)location { //坐标点的转化 NSInteger row = (location.y - 20)/44; self.sourceRect = CGRectMake(0, row * 44 + 20, [UIScreen mainScreen].bounds.size.width, 44); self.selectedPath = [NSIndexPath indexPathForItem:row inSection:0]; // 如果row越界了,返回NO 不处理peek手势 NSLog(@"当前所在的行---%zd",self.selectedPath.row); return (self.selectedPath.row > 5) ? NO : YES; }
实现peek上拉菜单
//在peek打开的控制器里遵守协议
@interface JYPopViewController ()<UIViewControllerPreviewingDelegate>
//设置菜单项
//peek上拉菜单 - (NSArray<id<UIPreviewActionItem>> *)previewActionItems { UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"确认" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { NSLog(@"点击了确认"); }]; UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"取消" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { NSLog(@"点击了取消"); }]; NSArray *actions =@[action1,action2]; return actions; }
相关文章推荐
- iOS-安装CocoaPods 配置第三方类库
- iOS-第三方库MJExtension使用 解析Json数据
- 谈谈iOS开发过程中的坑
- IOS 此证书的签发者无效解决方法
- IOS,ARC类型转换,显示转换 id 和 void *
- IOS,异常捕获信息上报
- IOS开发证书变成“此证书的签发者无效”解决方法
- iOS Crash 处理办法
- iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)
- IOS第一天_关键字与运算符
- IOS TableView详解
- Missing iOS Distribution signing identity问题解决
- iOS 个别页面强制横屏,其他页面竖屏
- iOS: 如何判断字符串是否相等?
- iOS - RunLoop
- 戴尔N5110装WIN10的体验
- ios配置文件出现错误
- iOS - Runtime
- 此证书的签发者无效Missing iOS Distribution signing identity问题解决
- ios修改NavigationController的背景颜色