桌面图标点击
需要在AppDelegate
里面进行代码编写。
1、创建方式
/** type 唯一标示r符
* localizedTitle 标题
* localizedSubtitle 副标题
* icon UIApplicationShortcutIcon对象
* userInfo 传递信息
*/
// 使用系统提供的图标生成UIApplicationShortcutIcon对象
UIApplicationShortcutItem *shoreItem1 = [[UIApplicationShortcutItem alloc] initWithType:@"type1"
localizedTitle:@"标题"
localizedSubtitle:@"副标题"
icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeCompose]
userInfo:nil];
// 使用自定义图片生成UIApplicationShortcutIcon对象
UIApplicationShortcutItem *shoreItem2 = [[UIApplicationShortcutItem alloc] initWithType:@"type2"
localizedTitle:@"标题2"
localizedSubtitle:@"副标题2"
icon:[UIApplicationShortcutIcon iconWithTemplateImageName:@"验证码"]
userInfo:nil];
[UIApplication sharedApplication].shortcutItems = @[shoreItem1, shoreItem2];
注:系统的UIApplicationShortcutIcon样式,自己去研究吧!点击这个是官方地址
2、点击回调,可以根据shortcutItem.type
进行判断点击的是哪个item
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
NSLog(@"点击了%@", shortcutItem);
}
应用内,点击进行页面操作
1、遵循代理UIViewControllerPreviewingDelegate
2、判断设备是否支持
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable){
[self registerForPreviewingWithDelegate:self sourceView:self.view];
NSLog(@"3D Touch 可用!");
} else {
NSLog(@"3D Touch 不可用!");
}
3、实现代理方法
- (nullable UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
NextViewController *vc = [[NextViewController alloc] init];
return vc;
}
-(void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
[self showViewController:viewControllerToCommit sender:self];
}
4、在需要显示的页面里面调用- (NSArray<id<UIPreviewActionItem>> *)previewActionItems
添加Items
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems {
UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"标题1" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"click---标题1");
}];
UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"标题2" style:UIPreviewActionStyleSelected handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"click---标题2");
}];
UIPreviewAction *action3 = [UIPreviewAction actionWithTitle:@"标题3" style:UIPreviewActionStyleDestructive handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"click---标题3");
}];
NSArray *actions = @[action1,action2,action3];
return actions;
}
温馨提示
-
点击App图标显示最分享按钮,是苹果给上架App添加的
IMG_2873.PNG -
点击分享的效果
IMG_2872.PNG
网友评论