3D Touch
2015-11-09 12:45
309 查看
3D Touch 使用简介
参照:SBShortcutMenuSimulator
示例
(1)桌面3D-Touch(Home shortcut)
静态方式
动态方式
AppDelegate
(2)预览(Peek and Pop)
Peek由一个可响应事件的View触发,默认是关闭的,我们需要通过控制器的registerForPreviewingWithDelegate: sourceView:方法注册,第一个参数为UIViewControllerPreviewingDelegate的代理,Peek触发轻压时会调用其previewingContext:viewControllerForLocation方法,重压时会调用previewingContext:commitViewController:方法。第二个参数为触发Peek事件的源视图
1.ViewController中
准备工作
(1)mac 10.11; xcode 7.1; simulator ios 9.1 (2)配置simulator(用于支持3D-Touch)
参照:SBShortcutMenuSimulator
示例
(1)桌面3D-Touch(Home shortcut)
静态方式
1.打开工程info.plist 添加如下信息:
<key>UIApplicationShortcutItems</key> <array> <dict> <key>UIApplicationShortcutItemIconType</key> <string>UIApplicationShortcutIconTypeShare</string> <key>UIApplicationShortcutItemTitle</key> <string>3d_touch</string> <key>UIApplicationShortcutItemType</key> <string>hello_touch</string> </dict> </array>
注:UIApplicationShortcutItems:桌面shortcut UIApplicationShortcutItemTitle:标题 UIApplicationShortcutItemType:类型 参照官方文档:
https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIApplicationShortcutItem_class/index.html
动态方式
AppDelegate
//配置shortcutItems - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. UIApplicationShortcutItem *shortItem1 = [[UIApplicationShortcutItem alloc] initWithType:@"Share" localizedTitle:@"分享"]; UIApplicationShortcutItem *shortItem2 = [[UIApplicationShortcutItem alloc] initWithType:@"Hello" localizedTitle:@"测试"]; NSArray *shortItems = [[NSArray alloc] initWithObjects:shortItem1, shortItem2, nil]; NSLog(@"%@", shortItems); [[UIApplication sharedApplication] setShortcutItems:shortItems]; return YES; } //在此响应点击事件 - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{ if ([shortcutItem.localizedTitle isEqual: @"测试"]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"3D" message:@"hello world" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; return; } }
(2)预览(Peek and Pop)
Peek由一个可响应事件的View触发,默认是关闭的,我们需要通过控制器的registerForPreviewingWithDelegate: sourceView:方法注册,第一个参数为UIViewControllerPreviewingDelegate的代理,Peek触发轻压时会调用其previewingContext:viewControllerForLocation方法,重压时会调用previewingContext:commitViewController:方法。第二个参数为触发Peek事件的源视图
1.ViewController中
注册代理:UIViewControllerPreviewingDelegate [self registerForPreviewingWithDelegate:self sourceView:self.view];
实现代理方法: //POP 重按 - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit{ [self showViewController:viewControllerToCommit sender:self]; } //显示Peek窗口 轻按 - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{ //TODO ImageViewController *ImageViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"ImageViewController"]; ImageViewController.preferredContentSize = CGSizeMake(0.0f,300); CGRect rect = CGRectMake(10, location.y - 10, self.view.frame.size.width - 20,20); previewingContext.sourceRect = rect; return ImageViewController; }
相关文章推荐
- 3D设计 Adobe Acrobat 3D 8.1.0 英文版 下载
- jquery带翻页动画的电子杂志代码分享
- jquery 3D 标签云示例代码
- jquery实现叠层3D文字特效代码分享
- Android的Touch事件处理机制介绍
- js的touch事件的实际引用
- Android编程实现3D滑动旋转效果的方法
- 一个很有趣3D球状标签云兼容IE8
- javascript实现3D变换的立体圆圈实例
- JS实现3D图片旋转展示效果代码
- Android Touch事件分发过程详解
- js实现3D图片逐张轮播幻灯片特效代码分享
- Ubuntu 3D 桌面
- Secnha Commands 3 使用详解(从创建到打包)
- sencha touch 彩色图标按钮(button+ico)
- Unity3D上路_01-2D太空射击游戏
- Unity3D上路_02-第一视角射击游戏
- Unity3D上路_03-塔防游戏
- Unity3D上路_04-基础资源介绍
- Unity3D上路_05-网络相关