iOS 3D Touch 和国际化

2016-04-14  本文已影响200人  犯傻小二

3DTouch

1 通过主屏幕的应用Icon,我们可以用3D Touch呼出一个菜单,进行快速定位应用功能模块相关功能的开发。如下图

3D touch.png
静态添加.png
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的交互,会使交互控件周围模糊

按下.png

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

继续深按.png

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

进一步交互.png
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.png ![2.png](https://img.haomeiwen.com/i1304617/5df4bfcf728dc337.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/310) 中文样式.png
英文样式.png App名字.png
上一篇 下一篇

猜你喜欢

热点阅读