3D-touch,小试身手

在启动页进行操作

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

初始化3D-touch

    application.applicationSupportsShakeToEdit =YES;

    struct utsname systemInfo;

    uname(&systemInfo);

    NSString *deviceString = [NSStringstringWithCString:systemInfo.machineencoding:NSUTF8StringEncoding];

    

    if ([deviceString isEqualToString:@"iPhone8,1"] || [deviceStringisEqualToString:@"iPhone8,2"]) {

        [selfconfigShortCutItems];

    }

    return YES;

}

#pragma mark -3d Touch打开

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    [self.windowendEditing:YES];

}

/** 创建shortcutItems */

- (void)configShortCutItems {

    

    NSMutableArray *shortcutItems = [NSMutableArrayarray];


    UIApplicationShortcutItem *item1 = [[UIApplicationShortcutItemalloc] initWithType:@"1"localizedTitle:@"预约挂号"localizedSubtitle:nilicon:[UIApplicationShortcutIconiconWithTemplateImageName:@"icon_register55.png"]userInfo:nil];

    

    UIApplicationShortcutItem *item2 = [[UIApplicationShortcutItemalloc] initWithType:@"2"localizedTitle:@"当天挂号"localizedSubtitle:nilicon:[UIApplicationShortcutIconiconWithTemplateImageName:@"icon_same-day13.png"]userInfo:nil];


    [shortcutItems addObject:item1];

    [shortcutItems addObject:item2];

    [[UIApplicationsharedApplication] setShortcutItems:shortcutItems];

}


/** 处理shortcutItem */

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

    

    switch (shortcutItem.type.integerValue) {

        case 1: {

            [[NSNotificationCenterdefaultCenter] postNotificationName:@"gotoVc"object:selfuserInfo:@{@"type":@"1"}];

            break;

        }

        case 2: {

            [[NSNotificationCenterdefaultCenter] postNotificationName:@"gotoVc"object:selfuserInfo:@{@"type":@"2"}];

            break;

        }

        default:

            break;

    }

}

在展示页面操作

初始化通知

- (void)viewDidLoad {


     [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(gotoVc:)name:@"gotoVc"object:nil];

    

}

#pragma mark 通知相关


- (void)dealloc {

    [[NSNotificationCenterdefaultCenter] removeObserver:self];

}

处理通知

- (void)gotoVc:(NSNotification *)noti {

    NSString *type = noti.userInfo[@"type"];

    DH_AppointmentController *appointMent = [[DH_AppointmentControlleralloc] init];

    if ([type isEqualToString:@"1"]) {

        appointMent.whiceTag = @"0";

        [self.navigationControllerpushViewController:appointMent animated:YES];

    } else if ([typeisEqualToString:@"2"]) {

        appointMent.whiceTag = @"1";

        [self.navigationControllerpushViewController:appointMent animated:YES];

    }

}

小结:此技术不难掌握,但由于刚出来,资料不是很多,掌握这三步,基本可以解决问题。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值