美文网首页
iOS开发3DTouch功能的实现

iOS开发3DTouch功能的实现

作者: Sunshine丶宇天 | 来源:发表于2017-03-23 16:18 被阅读106次

开发环境及调试设备支持:

Xcode7或以上,iOS9或以上,iPhone6s或以上

3DTouch功能主要分为两部分:

1、主屏幕icon上的快捷标签(Home Screen Quick Actions)

主屏幕icon上的快捷标签的实现方式有两种,

1.1在工程文件info.plist里静态设置

静态设置(在info.plist)中添加如下字段:

静态添加.png

效果如下:

静态添加效果.png

1.2代码的动态实现。

动态添加需要Application在iOS9之后新增的一个属性:

@property (nullable, nonatomic, copy) NSArray*shortcutItems NS_AVAILABLE_IOS(9_0) __TVOS_PROHIBITED;

然后在项目中添加代码:

动态添加代码.png 动态添加效果.png

下面列举一下UIApplicationShortcutItem每个参数的含义:

UIApplicationShortcutItem.png

2、Peek and Pop

1、注册(在哪个页面上使用该功能就注册在哪个页面上)

[self registerForPreviewingWithDelegate:selfsourceView:cell];

2、继承协议UIViewControllerPreviewingDelegate

3、实现UIViewControllerPreviewingDelegate方法


//peek(预览)- (nullable UIViewController *)previewingContext:(id)previewingContext viewControllerForLocation:(CGPoint)location

{

//获取按压的cell所在行,[previewingContext sourceView]就是按压的那个视图

NSIndexPath *indexPath = [_myTableView indexPathForCell:(UITableViewCell* )[previewingContext sourceView]];

//设定预览的界面

MyPreviewingViewController *childVC = [[MyPreviewingViewController alloc] init];

childVC.preferredContentSize = CGSizeMake(0.0f,500.0f);

childVC.myStr = [NSString stringWithFormat:@"我是%@,用力按一下进来-------",_myArray[indexPath.row]];

//调整不被虚化的范围,按压的那个cell不被虚化(轻轻按压时周边会被虚化,再少用力展示预览,再加力跳页至设定界面)

CGRect rect = CGRectMake(0, 0, self.view.frame.size.width,40);

previewingContext.sourceRect = rect;

//返回预览界面

return childVC;

}


//pop(按用点力进入)- (void)previewingContext:(id)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {

//    [self.view addSubview: viewControllerToCommit.view];

[self showViewController:viewControllerToCommit sender:self];

}


4、当弹出预览时,上滑预览视图,出现预览视图中快捷选项- (NSArray> *)previewActionItems {

// setup a list of preview actions

UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"删除" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"你点了-删除" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];

[alert show];

}];

UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"置顶" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"点-置顶" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];

[alert show];

}];

UIPreviewAction *action3 = [UIPreviewAction actionWithTitle:@"嘎哈" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"不嘎哈" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];

[alert show];

}];

NSArray *actions = @[action1,action2,action3];

// and return them (return the array of actions instead to see all items ungrouped)

return actions;

}

到此,3D Touch简单的使用就基本上实现了,如果以上有什么理解错误的地方,欢迎大家交流讨论。

相关文章

  • ios开发实现画板功能

    ios开发实现画板功能 ios开发实现画板功能

  • iOS开发中添加3DTouch功能

    iOS开发中添加3DTouch功能 在AppDelegate入口类的入口方法- (BOOL)application...

  • iOS开发3DTouch功能的实现

    开发环境及调试设备支持: Xcode7或以上,iOS9或以上,iPhone6s或以上 3DTouch功能主要分为两...

  • 3D Touch功能

    一、功能介绍: 开发环境及调试设备:Xcode7或以上,iOS9或以上,iPhone6s或以上3DTouch功能主...

  • 3DTouch 使用

    iOS9之后使用3DTouch 3DTouch功能主要分为两大块:主屏幕Icon上的Quick Action;Pe...

  • iOS开发 实现3DTouch

    1.添加3DTouch (我是自己封装的 只是在app 启动的时候吊起) 1.1判断是不是可以使用(ios9 之前...

  • iOS 3Dtouch功能开发

    3Dtouch(三维触控)是iPhone 6S以上机型有的功能,主要有两个使用场景:一个是APP图标重按后浮出快捷...

  • iOS APP开发添加3D Touch

    本文就iOS开发中如何集成3DTouch做下简单的讲解。 开发环境及调试设备:Xcode7或以上,iOS9或以上,...

  • iOS NFC 加密功能实现

    ios NFC加密功能实现 前言:记录一下ios开发中NFC添加密码功能,卡类型为(NFCMiFareTag --...

  • Swift开发之3DTouch实用演练

    Swift开发之3DTouch实用演练 Swift开发之3DTouch实用演练

网友评论

      本文标题: iOS开发3DTouch功能的实现

      本文链接:https://www.haomeiwen.com/subject/ouaznttx.html