3D Touch
来源:互联网 发布:gta5精简优化版 编辑:程序博客网 时间:2024/06/15 19:51
//1,桌面重压app图标/**需要在info.plist中进行配置 添加:UIApplicationShortcutItems (数组,元素是字典,多个title就多个item); 字典中有5个key, 必要的(required): UIApplicationShortcutItemType:唯一标识的字符串,用来在代码中进行判断点击的哪个title UIApplicationShortcutItemTitle:标题 可选的(optional) UIApplicationShortcutItemSubtitle:子标题,显示在title下面,如果指定了subtitle,title只会显示一行,显示不下的以...的形式显示 UIApplicationShortcutItemIconFile:图片名字(自定义) UIApplicationShortcutItemIconType:枚举,系统自带的图片,包括:UIApplicationShortcutIconTypeCompose之类的,可以点进去看的,或者参考http://blog.csdn.net/baidu_32469997/article/details/51192500 UIApplicationShortcutItemUserInfo:字典类型,具体用处不清楚*///在APPDelegate中- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {//这里根据UIApplicationShortcutItemType来判断要做的动作 if ([shortcutItem.type isEqualToString:@"share"]) { UIButton *btn = [[UIButton alloc]initWithFrame:[UIScreen mainScreen].bounds]; [btn setImage:[UIImage imageNamed:@"shareLogo"] forState:UIControlStateNormal]; [[[UIApplication sharedApplication] keyWindow] addSubview:btn]; [btn setBackgroundColor:[UIColor whiteColor]]; btn.imageView.contentMode = UIViewContentModeScaleAspectFit; [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; } else if ([shortcutItem.type isEqualToString:@"dianij"]) { NSLog(@"share"); }}
//例: <key>UIApplicationShortcutItems</key> <!--数组,可以设置多个选项--> <array> <dict> <!--图片,暂时是纯黑的,可以空心--> <key>UIApplicationShortcutItemIconFile</key> <string>wt_unity_refreshing</string> <!--标题--> <key>UIApplicationShortcutItemTitle</key> <string>标题</string> <!--唯一标识的字符串,用来在代码中进行判断--> <key>UIApplicationShortcutItemType</key> <string>dianji</string> </dict> <dict> <!--唯一标识的字符串,用来在代码中进行判断--> <key>UIApplicationShortcutItemType</key> <string>share</string> <!--标题--> <key>UIApplicationShortcutItemTitle</key> <string>选择</string> <!--图片--> <key>UIApplicationShortcutItemIconFile</key> <string>wt_unity_shareLogo</string> </dict> </array>
//二.在viewController中使用3D Touch//1.控制器注册成为3DTouch响应[self registerForPreviewingWithDelegate:self sourceView:_tableView];//2.实现 UIViewControllerPreviewingDelegate 协议- (nullable UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location { //location是相对于previewingContext.sourceView的view中的位置 UITableView *table = (UITableView *)previewingContext.sourceView; //这是目前我能想到的一个确定点击哪个cell的方法,如果cell高度不固定暂时还不知道怎么弄 , UITableViewCell *cell =[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:(NSInteger)location.y/cellHeight]]; SecondViewController *secondVC = [[SecondViewController alloc]init]; [secondVC.titleLable setText:cell.textLabel.text]; //要有上滑手势还需要在secondViewController中重写 - (NSArray<id<UIPreviewActionItem>> *)previewActionItems 方法 return secondVC;}- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit { [self showViewController:viewControllerToCommit sender:self];}//3.SecondViewController中重写 - (NSArray<id<UIPreviewActionItem>> *)previewActionItems方法- (NSArray<id<UIPreviewActionItem>> *)previewActionItems {//三个type可以自己都试一下看看效果 UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"title1" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { NSLog(@"title1"); }]; UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"title2" style:UIPreviewActionStyleSelected handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { NSLog(@"selected"); }]; UIPreviewAction *action3 = [UIPreviewAction actionWithTitle:@"title3" style:UIPreviewActionStyleDestructive handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { NSLog(@"销毁");//UIPreviewActionStyleDestructive应该是默认字体颜色是红色 }]; return @[action1, action2, action3];}
0 0
- 关于3D Touch
- 关于3D Touch
- 3D Touch初探
- 3D Touch大法
- 3D Touch
- ios 3D Touch
- 3D touch
- 3D Touch
- 3D Touch
- iphone 3D Touch
- 3D Touch入门
- 3D Touch APIs
- ios9 3D Touch
- 3D Touch详解
- 3D touch功能
- iOS 3D touch
- 3D Touch是什么?
- 3D Touch
- javascript去除字符串左右两端的空格
- 215. Kth Largest Element in an Array
- mac下安装brew遇到的问题总结
- 类目和延展的作用和区别?
- POJ 3421X-factor Chains【分解质因子+组合数学】
- 3D Touch
- 总结一下java中的位操作,运算优先级
- ApachePOI导出exce,设置单元格风格的属性和设置字体风格的属性的两个工具类,POI宽度和excel 像素转换
- 如何求两个矩形相交面积
- 查找--静态查找与动态查找
- MTK之UART串口收发数据
- SDAU练习二1011
- 不用导入SDK就可实现导航--URI方式跳转到各类地图进行导航
- 朴素贝叶斯的实际应用