iOS开发进阶

iOS开发实战:3D-touch,小试身手

2019-07-31  本文已影响0人  文竹_自然

16年技术总结,从自己的新浪搬过来!

在启动页进行操作

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

初始化3D-touch

  application.applicationSupportsShakeToEdit=YES;

 structutsnamesystemInfo;

 uname(&systemInfo);

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

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

    [selfconfigShortCutItems];

  }

 returnYES;

}

#pragma mark -3d Touch打开

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

{

  [self.windowendEditing:YES];

}

- (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];

  [shortcutItemsaddObject:item1];

  [shortcutItemsaddObject:item2];

  [[UIApplicationsharedApplication]setShortcutItems:shortcutItems];

}

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

 switch(shortcutItem.type.integerValue) {

   case1: {

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

     break;

    }

   case2: {

     [[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([typeisEqualToString:@"1"]) {

    appointMent.whiceTag=@"0";

    [self.navigationControllerpushViewController:appointMentanimated:YES];

  }elseif([typeisEqualToString:@"2"]) {

    appointMent.whiceTag=@"1";

    [self.navigationControllerpushViewController:appointMentanimated:YES];

  }

}

上一篇 下一篇

猜你喜欢

热点阅读