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

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

jeffaburt avatar kevin-lyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stpopuppreview's Issues

Overlap Image with ActionSheet

Hi kevin,

The image is overlapping on ActionSheet, See the attached image.
This situation occurs when the image is not download from server and popup appears before it.
After downloading and setting up the image .. this happen,

CGFloat imageWidth = [self.data[@"dimensions"][@"width"] doubleValue];
CGFloat imageHeight = [self.data[@"dimensions"][@"height"] doubleValue];

the above 2 lines will not work until the image downloaded.
So need to set the UI again after image downloading.

img_2435

Swift?

Hello, there is a swift example for this?

Thanks!!

Bug with header

I am facing an erro using STPopupPreviedw with MXSegmentedPager

Actually, I have no idea this problem is related to MXSegmentedPager

In the blurred background view, the frame is incorrect

To see the error, please, see the video demo

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

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

- (NSArray<STPopupPreviewAction *> *)previewActionsForPopupPreviewRecognizer:(STPopupPreviewRecognizer *)popupPreviewRecognizer{
    if (![popupPreviewRecognizer.view isKindOfClass:[CellFuturePost_CollectionViewCell class]]) {
        return nil;
    }
    CellFuturePost_CollectionViewCell *cell = popupPreviewRecognizer.view;
    STPopupPreviewAction * seePost = [STPopupPreviewAction actionWithTitle:@"Ver post" style:STPopupPreviewActionStyleDefault handler:^(STPopupPreviewAction *action, UIViewController *previewViewController) {
        [self.delegate openPost:cell.post];
    }];
    
    STPopupPreviewAction * like = [STPopupPreviewAction actionWithTitle:@"Like" style:STPopupPreviewActionStyleDefault handler:^(STPopupPreviewAction *action, UIViewController *previewViewController) {
        [self.delegate openLikes:cell.post];
    }];
    
    STPopupPreviewAction * comment = [STPopupPreviewAction actionWithTitle:@"Comment" style:STPopupPreviewActionStyleDefault handler:^(STPopupPreviewAction *action, UIViewController *previewViewController) {
        [self.delegate openComment:cell.post];
    }];
    return @[seePost, like, comment];
}

The error 'contentSizeInPopup should not be size zero'

// // ProfileViewController.h #import <UIKit/UIKit.h> #import <MBProgressHUD.h> #import <SDWebImage/UIImageView+WebCache.h> #import <STPopup/STPopup.h> @interface ProfileViewController : UIViewController<STPopupControllerTransitioning> @end
`
#import "ProfileViewController.h"

@interface ProfileViewController ()

@EnD

@implementation ProfileViewController

  • (void)viewDidLoad {
    [super viewDidLoad];

}

-(void)updateUserContactDetails:(NSString *)path Params:(NSDictionary *)params{

    STPopupController *popupController = [[STPopupController alloc] initWithRootViewController:[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"MobileUpdateOTP"]];
    popupController.style = STPopupStyleBottomSheet;
    [popupController presentInViewController:self];

}

#pragma mark - STPopupControllerTransitioning

  • (NSTimeInterval)popupControllerTransitionDuration:(STPopupControllerTransitioningContext *)context
    {
    return context.action == STPopupControllerTransitioningActionPresent ? 0.5 : 0.35;
    }

  • (void)popupControllerAnimateTransition:(STPopupControllerTransitioningContext *)context completion:(void (^)())completion
    {
    UIView *containerView = context.containerView;
    if (context.action == STPopupControllerTransitioningActionPresent) {
    containerView.transform = CGAffineTransformMakeTranslation(containerView.superview.bounds.size.width - containerView.frame.origin.x, 0);

      [UIView animateWithDuration:[self popupControllerTransitionDuration:context] delay:0 usingSpringWithDamping:1 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
          context.containerView.transform = CGAffineTransformIdentity;
      } completion:^(BOOL finished) {
          completion();
      }];
    

    }
    else {
    [UIView animateWithDuration:[self popupControllerTransitionDuration:context] delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
    containerView.transform = CGAffineTransformMakeTranslation(- 2 * (containerView.superview.bounds.size.width - containerView.frame.origin.x), 0);
    } completion:^(BOOL finished) {
    containerView.transform = CGAffineTransformIdentity;
    completion();
    }];
    }
    }

@EnD

#import <UIKit/UIKit.h>
#import <STPopup/STPopup.h>

@interface MobileUpdateOTPViewController : UIViewController

@EnD

#import "MobileUpdateOTPViewController.h"

@interface MobileUpdateOTPViewController ()

@EnD

@implementation MobileUpdateOTPViewController

  • (instancetype)init
    {
    if (self = [super init]) {
    self.title = @"Verification Code";
    self.contentSizeInPopup = CGSizeMake(300, 400);
    self.landscapeContentSizeInPopup = CGSizeMake(400, 200);
    }
    return self;
    }

  • (void)viewDidLoad
    {
    [super viewDidLoad];
    }

  • (void)viewDidLayoutSubviews
    {
    [super viewDidLayoutSubviews];
    }

@EnD
`

I'm getting error

[STPopupController contentSizeOfTopView], ~/Pods/STPopup/STPopup/STPopupController.m:536
2017-06-07 17:40:48.249014+0530: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'contentSizeInPopup should not be size zero.'

3D Touch usage for iphone 6s and above

If i'm not mistaken, this library applies on iphone which doesn't have 3D touch. How about iphone 6S and above ? It does have 3D touch, can i use this library to preview my image? Or should i put different code applied for it's 3D touch function ?

change Blur background

Is it possible to change the Blur background? Can I use the same functions as STPopup?

Action Buttons and arrow not visible.

After compiling latest library 1.0.3 with latest xcode and do not longer see action buttons and arrow.

Tried to use xcode layout debugger and it responds that backgroundContentView size is 0,0 at position 0,0;
screen shot 2017-11-20 at 10 51 03 pm

Expose long press gesture location

I've implemented 3d touch with a helper that receives the UICollectionView. From there I retrieve the pressed cell with the location from previewingContext:viewControllerForLocation:.

I'd like to add this popupPreviewRecognizer to the UICollectionView as well, but I need the gesture location for determining which cell was pressed.

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.