3DTouch
1 通过主屏幕的应用Icon,我们可以用3D Touch呼出一个菜单,进行快速定位应用功能模块相关功能的开发。如下图
- 1.1 静态添加
- 1.2 动态添加(代码添加)


if(self.window.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
UIMutableApplicationShortcutItem *shortItem1 = [[UIMutableApplicationShortcutItem alloc] initWithType:@"ECGAboutMeViewController" localizedTitle:@"关于我们" localizedSubtitle:@"" icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"tab_btn_setting-normal"] userInfo:@{@"icon" : @"helloIcon"}];
NSArray *shortItems = [[NSArray alloc] initWithObjects:shortItem1, nil];
// item 添加的个数
[[UIApplication sharedApplication] setShortcutItems:shortItems];
}
#pragma mark - 3D Touch
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
if ([[ECGUserCenter shareCenter] needLogin]) {
// 判断是否登录 未登录去登录
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Mine" bundle:nil];
} else {
if ([application.keyWindow.rootViewController isKindOfClass:[ECGTabbarViewController class]]) {
ECGTabbarViewController *tabBar = (ECGTabbarViewController *)application.keyWindow.rootViewController;
ECGNavigationViewController *navgation = tabBar.childViewControllers[3];
[tabBar setSelectedIndex:3];
[navgation popToRootViewControllerAnimated:YES];
if ([shortcutItem.localizedTitle isEqual: @"消息盒子"]) {
UIViewController *messageBox = [[NSClassFromString(shortcutItem.type) alloc] init];
[navgation pushViewController:messageBox animated:YES];
return;
} else if ([shortcutItem.localizedTitle isEqual: @"我的订单"]) {
UIViewController *myOrder = [[NSClassFromString(shortcutItem.type) alloc] init];
[navgation pushViewController:myOrder animated:YES];
return;
} else if ([shortcutItem.localizedTitle isEqual: @"关于我们"]) {
UIViewController *aboutMe = [[NSClassFromString(shortcutItem.type) alloc] init];
[navgation pushViewController:aboutMe animated:YES];
return;
}
}
}
}
2、peek and pop
这个功能是一套全新的用户交互机制,在使用3D Touch时,ViewController中会有如下三个交互阶段:
1)提示用户这里有3D Touch的交互,会使交互控件周围模糊

2)继续深按,会出现预览视图

3)通过视图上的交互控件进行进一步交互

if (self.traitCollection.forceTouchCapability== UIForceTouchCapabilityAvailable) {
[self registerForPreviewingWithDelegate:selfsourceView:cell];
} //注册
- (UIViewController*)previewingContext:(id <UIViewControllerPreviewing>)previewingContextviewControllerForLocation:(CGPoint)location {
CGPoint point = [previewingContext.sourceView convertPoint:location toView:self.tabView];
NSIndexPath *indexPath = [self.tabView indexPathForRowAtPoint:point]; // 获取 indexPath
}
- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContextcommitViewController:(UIViewController*)viewControllerToCommit
- (NSArray<id <UIPreviewActionItem>> *)previewActionItems//交互
App语言国际化
根据当前用户当前移动设备的语言自动将我们的app切换对应语言
- 1> 添加要支持的语言
- 2>点击“newfile”然后在弹出窗口左侧选择 IOS 的resource 项,在右侧就可以看到“String File”的图标。创建这个文件,命名为“InfoPlist”(一定是这个文件名) 就生成一个InfoPlist.strings文件;
- 3>选中InfoPlist.strings,在右边的Localization中点 “Localize”, 添加你需要的语言chinese(zh-Hans)类型的为简体中文,english
应该会自动添加上。 - 4> 重复步骤2,3 创建Localizable.Strings;
- 5> 在相应的.Strings文件中写 “key” = “value”





网友评论