/**需要在info.plist中进行配置
添加:UIApplicationShortcutItems (数组,元素是字典,多个title就多个item);
字典中有5个key,
必要的(required):
UIApplicationShortcutItemType:唯一标识的字符串,用来在代码中进行判断点击的哪个title
UIApplicationShortcutItemTitle:标题
可选的(optional)
UIApplicationShortcutItemSubtitle:子标题,显示在title下面,如果指定了subtitle,title只会显示一行,显示不下的以...的形式显示
UIApplicationShortcutItemIconFile:图片名字(自定义)
UIApplicationShortcutItemIconType:枚举,系统自带的图片,包括:UIApplicationShortcutIconTypeCompose之类的,可以点进去看的,或者参考http://blog.youkuaiyun.com/baidu_32469997/article/details/51192500
UIApplicationShortcutItemUserInfo:字典类型,具体用处不清楚
*/
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
if ([shortcutItem.type isEqualToString:@"share"]) {
UIButton *btn = [[UIButton alloc]initWithFrame:[UIScreen mainScreen].bounds];
[btn setImage:[UIImage imageNamed:@"shareLogo"] forState:UIControlStateNormal];
[[[UIApplication sharedApplication] keyWindow] addSubview:btn];
[btn setBackgroundColor:[UIColor whiteColor]];
btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
}
else if ([shortcutItem.type isEqualToString:@"dianij"]) {
NSLog(@"share");
}
}
//例:
<key>UIApplicationShortcutItems</key>
<array>
<dict>
<key>UIApplicationShortcutItemIconFile</key>
<string>wt_unity_refreshing</string>
<key>UIApplicationShortcutItemTitle</key>
<string>标题</string>
<key>UIApplicationShortcutItemType</key>
<string>dianji</string>
</dict>
<dict>
<key>UIApplicationShortcutItemType</key>
<string>share</string>
<key>UIApplicationShortcutItemTitle</key>
<string>选择</string>
<key>UIApplicationShortcutItemIconFile</key>
<string>wt_unity_shareLogo</string>
</dict>
</array>
[self registerForPreviewingWithDelegate:self sourceView:_tableView];
- (nullable UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
UITableView *table = (UITableView *)previewingContext.sourceView;
UITableViewCell *cell =[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:(NSInteger)location.y/cellHeight]];
SecondViewController *secondVC = [[SecondViewController alloc]init];
[secondVC.titleLable setText:cell.textLabel.text];
return secondVC;
}
- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
[self showViewController:viewControllerToCommit sender:self];
}
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems {
UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"title1" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"title1");
}];
UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"title2" style:UIPreviewActionStyleSelected handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"selected");
}];
UIPreviewAction *action3 = [UIPreviewAction actionWithTitle:@"title3" style:UIPreviewActionStyleDestructive handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"销毁");
}];
return @[action1, action2, action3];
}