? ? ? ? 在最近的需求中,需要用到3DTouch功能,看起來(lái)高大上的東西,其實(shí)用起來(lái)很簡(jiǎn)單,在這里簡(jiǎn)單的寫(xiě)一下用法...
總結(jié)起來(lái)3DTouch主要有三大功能: 第一點(diǎn):在外面開(kāi)辟快捷入口;當(dāng)然這個(gè)需要我們自己動(dòng)手去添加,至于添加的方式有兩種,第一種是靜態(tài)添加:
//靜態(tài)設(shè)置(在info.plist)中添加如下字段:uiapplicationShortcutltems在這下面添加 //uiapplicationShortcutltemsTitle(必選)這個(gè)鍵值設(shè)置標(biāo)簽的標(biāo)題uiapplicationShortcutltemsType(必選)這個(gè)鍵值設(shè)置一個(gè)快捷通道類型的字符串
這是在plist文件中添加
第二種方式就是動(dòng)態(tài)添加了:如下圖
添加這些東西需要在這個(gè)方法下執(zhí)行:- (BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary *)options;
添加以后就需要處理他的點(diǎn)擊事件跳轉(zhuǎn)到不同指定頁(yè)面:如下圖
效果如下:
第二個(gè)功能就是預(yù)覽功能:點(diǎn)擊圖片浮起周邊虛化并且上拉選項(xiàng)處理事件功能.實(shí)現(xiàn)這個(gè)功能需要先遵守系統(tǒng)的的一個(gè)協(xié)議<UIViewControllerPreviewingDelegate>然后去實(shí)現(xiàn)他的協(xié)議方法,在實(shí)現(xiàn)協(xié)議方法之前需要先注冊(cè)當(dāng)前頁(yè)面
/**注冊(cè)當(dāng)前view (在哪個(gè)頁(yè)面上使用該功能就注冊(cè)在哪個(gè)頁(yè)面上)*/
[selfregisterForPreviewingWithDelegate:selfsourceView:self.view];
注意事項(xiàng):需要先創(chuàng)建一個(gè)
注意:這個(gè)協(xié)議方法是在需要展示的那個(gè)控制器中實(shí)現(xiàn)的
//4、當(dāng)彈出預(yù)覽時(shí)巧颈,上滑預(yù)覽視圖位他,出現(xiàn)預(yù)覽視圖中快捷選項(xiàng)
/**
預(yù)覽時(shí)滑動(dòng)底部菜單添加竹捉,在要展示的ViewController中實(shí)現(xiàn)UIViewControllerPreviewingDelegate的協(xié)議
重寫(xiě)方法代理方法- (NSArray> *)previewActionItems;
*/
-(NSArray> *)previewActionItems
{
UIPreviewAction*p1 = [UIPreviewActionactionWithTitle:@"選項(xiàng)1"style:UIPreviewActionStyleDefaulthandler:^(UIPreviewAction*_Nonnullaction,UIViewController*_NonnullpreviewViewController) {
NSLog(@"1111111");
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@""message:@"111111"delegate:selfcancelButtonTitle:@"OK"otherButtonTitles:nil,nil];
[alertshow];
}];
UIPreviewAction*p2 = [UIPreviewActionactionWithTitle:@"選項(xiàng)2"style:UIPreviewActionStyleSelectedhandler:^(UIPreviewAction*_Nonnullaction,UIViewController*_NonnullpreviewViewController) {
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"你點(diǎn)了-刪除"message:nildelegate:nilcancelButtonTitle:@"確定"otherButtonTitles:nil];
[alertshow];
}];
UIPreviewAction*p3 = [UIPreviewActionactionWithTitle:@"選項(xiàng)3"style:UIPreviewActionStyleDestructivehandler:^(UIPreviewAction*_Nonnullaction,UIViewController*_NonnullpreviewViewController) {
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"點(diǎn)-置頂"message:nildelegate:nilcancelButtonTitle:@"確定"otherButtonTitles:nil];
[alertshow];
}];
return@[p1,p2,p3];
}
到此為止關(guān)于3DTouch的基礎(chǔ)應(yīng)用就搞定了....