1.配置ShortcutItem需要在info.plist中进行配置
添加一项叫做UIApplicationShortcutItems 数组类型
然后每一个Item是字典 分别添加 UIApplicationShortcutItemIconType(icon 的类型),UIApplicationShortcutItemTitle(item的标题),UIApplicationShortcutItemType(类型),UIApplicationShortcutItemUserInfo(存用户基本信息)
//获取一个应用程序对象的shortcutItem列表
UIApplicationShortcutItem *mutableItem = [[UIApplicationShortcutItem alloc] initWithType:@"UITouchText.share" localizedTitle:@"分享"];
[app setShortcutItems:@[mutableItem]];
id existingShortcutItems = [app shortcutItems];
2.在AppDelegate 中重写方法
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void(^)(BOOL succeeded))completionHandler
{
//通过type来决定点击每一个shourtcutItem 再作处理
if([shortcutItem.type isEqualToString:@"UITouchText.share"]){
}
}
peek 和 pop
需要先注册
if(self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable){
[self registerForPreviewingWithDelegate:self sourceView:self.collectionView];
}
UIViewController 中要遵守 UIViewControllerPreviewingDelegate
重写两个方法
- (nullable UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location NS_AVAILABLE_IOS(9_0);
这里是需要return 一个viewController(需要预览的ViewController)
可以通过location来判断点击了哪个cell
NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:location];
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
return 之后 viewController就会走生命周期 viewDidLoad 等方法,,当我们松手消失的时候会走dealloc方法,我们可以在此执行一个block来回调消失时候的处理
设置这个 previewingContext.sourceRect 强压时候的高亮显示区域
detailVC.preferredContentSize = CGSizeMake(0.0, 320.0); 显示的预览View的大小
- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit NS_AVAILABLE_IOS(9_0);
这个是我们点击放大进入的时候会回调的方法,,你可以show viewController 或者 pushViewController (需要把动画去掉)
- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
{
// [self showViewController:viewControllerToCommit sender:self];
[FrameManager pushViewController:viewControllerToCommit animated:NO];
}
弹出PreviewView时候向上拖会有操作按钮,基本代码如下
在ViewController里面的方法中重写这个方法
初始化一个UIPreviewAction数组
arrayPreviewActions = @[
[UIPreviewAction actionWithTitle:@"进入直播间" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
[weakSelf pushMobileLiveRoomViewController:previewViewController];
}]];
-(NSArray<id<UIPreviewActionItem>> *)previewActionItems
{
return arrayPreviewActions;
}