STPopupPreview 1.0.5

STPopupPreview 1.0.5

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新版本2019年6月

Kevin Lin维护。



  • Kevin Lin

STPopupPreview CI Status Version License

STPopupPreview 使用长按手势在非3D Touch设备上启用快速预览页面。支持预览动作。这个想法受到Instagram的启发。

它基于STPopup(一个提供STPopupController的库,就像弹出样式中的 UINavigationController 一样工作)。STPopup 和 STPopupPreview 都支持iOS 7以上版本。

演示

一个简单的演示显示了从我Instagram中的图片

STPopupPreviewDemo

特性

  • 长按预览,松开取消。
  • 向上滑动显示预览动作。
  • 易于集成。

开始使用

CocoaPods

platform: ios, '7.0'
pod 'STPopupPreview'

Carthage

github "kevin0571/STPopupPreview"

*请不要忘记将 STPopupPreview.framework 和 STPopup.framework 拖到链接框架中。

用法

导入头文件

#import <STPopupPreview/STPopupPreview.h>

将弹出预览识别器附加到视图

CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([CollectionViewCell class]) forIndexPath:indexPath];
if (!cell.popupPreviewRecognizer) {
    cell.popupPreviewRecognizer = [[STPopupPreviewRecognizer alloc] initWithDelegate:self];
}

实现 STPopupPreviewRecognizerDelegate

返回预览视图控制器。在调用 "viewDidLoad" 之前,预览视图控制器应设置 "contentSizeInPopup"。有关更多信息,请参阅 STPopup 文档。

- (UIViewController *)previewViewControllerForPopupPreviewRecognizer:(STPopupPreviewRecognizer *)popupPreviewRecognizer
{
    if (![popupPreviewRecognizer.view isKindOfClass:[CollectionViewCell class]]) {
        return nil;
    }
    
    CollectionViewCell *cell = popupPreviewRecognizer.view;
    
    PreviewViewController *previewViewController = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([PreviewViewController class])];
    previewViewController.data = cell.data;
    previewViewController.placeholderImage = cell.imageView.image;
    return previewViewController;
}

返回用于展示预览视图控制器的视图控制器。大多数情况下将是最当前的视图控制器。

- (UIViewController *)presentingViewControllerForPopupPreviewRecognizer:(STPopupPreviewRecognizer *)popupPreviewRecognizer
{
    return self;
}

返回在向上滑动时想要展示的预览动作。如果没有预览动作,则可以返回 nil。

- (NSArray<STPopupPreviewAction *> *)previewActionsForPopupPreviewRecognizer:(STPopupPreviewRecognizer *)popupPreviewRecognizer
{
    return @[ [STPopupPreviewAction actionWithTitle:@"Like" style:STPopupPreviewActionStyleDefault handler:^(STPopupPreviewAction *action, UIViewController *previewViewController) {
        // Action handler
    }] ];
}

仅在3D Touch不可用时启用 STPopupPreview

BOOL isForceTouchAvailable = [self respondsToSelector:@selector(traitCollection)] &&
    [self.traitCollection respondsToSelector:@selector(forceTouchCapability)] &&
    self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable;
if (!isForceTouchAvailable) {
    if (!cell.popupPreviewRecognizer) {
        cell.popupPreviewRecognizer = [[STPopupPreviewRecognizer alloc] initWithDelegate:self];
    }
}

问题 & 联系

  • 如果您对使用有任何疑问,请参阅示例项目以获取更多详细信息。
  • 如果您发现任何错误,请提交一个 问题