Giter VIP home page Giter VIP logo

stpopuppreview's Introduction

STPopupPreview CI Status Version License

STPopupPreview uses long press gesture to enable quick preview of a page on non 3D Touch devices. Preview actions are also supported. This idea is inspired by Instagram.

It is built on top of of STPopup(a library provides STPopupController, which works just like UINavigationController in popup style). Both STPopup and STPopupPreview support iOS 7+.

Demo

A simple demo shows images from my Instagram

STPopupPreviewDemo

Features

  • Long press to preview, release to dismiss.
  • Slide up to show preview actions.
  • Easy integration.

Get Started

CocoaPods

platform: ios, '7.0'
pod 'STPopupPreview'

Carthage

github "kevin0571/STPopupPreview"

*Don't forget to drag both STPopupPreview.framework and STPopup.framework into linked frameworks.

Usage

Import header file

#import <STPopupPreview/STPopupPreview.h>

Attach popup preview recognizer to view

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

Implement STPopupPreviewRecognizerDelegate

Return the preview view controller. The preview view controller should have "contentSizeInPopup" set before its "viewDidLoad" called. More about this please read the document of 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;
}

Return a view controller to present the preview view controller. Most of the time it will be the current view controller.

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

Return the preview actions you want to show when slides up. It can be nil if you don't have any preview actions.

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

Enable STPopupPreview only if 3D Touch is not available

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];
    }
}

Issues & Contact

  • If you have any question regarding the usage, please refer to the example project for more details.
  • If you find any bug, please submit an issue.

stpopuppreview's People

Contributors

kevin-lyn avatar jeffaburt avatar

Watchers

James Cloos avatar Calvin Sugianto avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.