3DTouchDemo主要的內(nèi)容為四塊
1、Home Screen Quick Actions(主屏幕快捷操作)
主屏幕頁面的快捷操作按鈕需要 在APPDelegate中添加相應(yīng)的UIApplicationShortcutItem
//add ShortcutItem
-(void)addShortcutItems:(UIApplication *)application{
//這里給定的圖片,系統(tǒng)會再處理成 自己需要的圖片
UIApplicationShortcutIcon * icon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"personal"];
UIMutableApplicationShortcutItem * itemtwo = [[UIMutableApplicationShortcutItem alloc]initWithType:@"two" localizedTitle:@"主功能1" localizedSubtitle:@"副標題" icon:icon userInfo:nil];
application.shortcutItems = @[itemtwo];}}
點擊相應(yīng)的按鈕會觸發(fā)APPDelegate 的事件
-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
[[NSNotificationCenter defaultCenter]postNotificationName:@"shortcutItemNotify" object:shortcutItem.type];}
2、Peek/Pop(預(yù)覽和彈出)
該功能實現(xiàn)分三步,
(1)、遵守協(xié)議 UIViewControllerPreviewingDelegate
(2)、注冊? ? [self registerForPreviewingWithDelegate:self sourceView:self.view];
(3)、實現(xiàn)代理方法:
-(UIViewController *)previewingContext:(id)previewingContext viewControllerForLocation:(CGPoint)location;//Peek預(yù)覽時返回的控制器
- (void)previewingContext:(id)previewingContext commitViewController:(UIViewController *)viewControllerToCommit//再次按壓Pop的控制器
3、HTML鏈接預(yù)覽功能
這個主要是Safari瀏覽器的功,在項目中引入
#import<SafariServices/SafariServices.h>
在需要的地方添加Safari的跳轉(zhuǎn)代碼
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 : 最大可能的力度
這里給出一個實際應(yīng)用的范例,根據(jù)按壓的力度去改變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