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
网友评论