iOS 3DTouchDemo

3DTouchDemo主要的内容为四块

1、Home Screen Quick Actions(主屏幕快捷操作)

主屏幕页面的快捷操作按钮需要 在APPDelegate中添加相应的UIApplicationShortcutItem

//add ShortcutItem

-(void)addShortcutItems:(UIApplication *)application{

//这里给定的图片,系统会再处理成 自己需要的图片

UIApplicationShortcutIcon * icon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"personal"];

UIMutableApplicationShortcutItem * itemtwo = [[UIMutableApplicationShortcutItem alloc]initWithType:@"two" localizedTitle:@"主功能1" localizedSubtitle:@"副标题" icon:icon userInfo:nil];

application.shortcutItems = @[itemtwo];}}

点击相应的按钮会触发APPDelegate 的事件

-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{

[[NSNotificationCenter defaultCenter]postNotificationName:@"shortcutItemNotify" object:shortcutItem.type];}

2、Peek/Pop(预览和弹出)

该功能实现分三步,

(1)、遵守协议 UIViewControllerPreviewingDelegate

(2)、注册    [self registerForPreviewingWithDelegate:self sourceView:self.view];

(3)、实现代理方法:

-(UIViewController *)previewingContext:(id)previewingContext viewControllerForLocation:(CGPoint)location;//Peek预览时返回的控制器

- (void)previewingContext:(id)previewingContext commitViewController:(UIViewController *)viewControllerToCommit//再次按压Pop的控制器

3、HTML链接预览功能

这个主要是Safari浏览器的功,在项目中引入

#import<SafariServices/SafariServices.h>

在需要的地方添加Safari的跳转代码

SFSafariViewController *sf = [[SFSafariViewController alloc]initWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];

[self.navigationController pushViewController:sf animated:YES];

4、Force Properties(按压力度)

ios9中添加在UITouch中添加了2个属性,用于感知手指按下的力度

force : 手指按下的力度

maximumPossibleForce : 最大可能的力度

这里给出一个实际应用的范例,根据按压的力度去改变view背景色

-(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event{

if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {

UITouch * touch = touches.anyObject;

NSLog(@"force:%f,maximumPossibleForce:%ff",touch.force,touch.maximumPossibleForce);

self.view.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:touch.force/touch.maximumPossibleForce alpha:1.0];

}}

最后附上Demo地址:3DTouchDemo

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 专著:http://www.jianshu.com/p/3443a3b27b2d 1.简单的介绍一下3D Touc...
    violafa阅读 1,079评论 1 0
  • 前言 关于这篇文章 由于iPhone 6S发布不到一年的时间,很多新特性、新技术还未普遍,不管是3D Touch的...
    Tangentw阅读 4,719评论 8 18
  • 3D Touch简介 2015年,苹果发布了iOS9以及iphone6s/iphone6s Plus,其中最具有创...
    简简蜗牛阅读 694评论 0 0
  • 3D Touch简介 2015年,苹果发布了iOS9以及iphone6s/iphone6s Plus,其中最具有创...
    爱恨的潮汐阅读 435评论 0 2
  • 1.简单的介绍一下3D Touch 3D Touch的触控技术,被苹果称为新一代多点触控技术。其实,就是此前在Ap...
    Camille_chen阅读 12,305评论 19 33

友情链接更多精彩内容