Giter Club home page Giter Club logo

nytphotoviewer's Introduction

NYTPhotoViewer

Carthage compatible

NYTPhotoViewer is a slideshow and image viewer that includes double-tap to zoom, captions, support for multiple images, interactive flick to dismiss, animated zooming presentation, and more.

Demo GIF

Usage

Usage is simple, with the option for more complicated customization when needed through a delegate relationship. In the most basic implementation, just initialize the view controller with an array of photo objects and present it as normal:

NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:photos];
[self presentViewController:photosViewController animated:YES completion:nil];

Running the Example

Clone this locally, then in your local workspace of the NYTPhotoViewer repo, run ./scripts/bootstrap, then open Examples/NYTPhotoViewer.xcworkspace. You'll see targets for a Swift and Objective-C app.

Installation

Swift Package Manager

NYTPhotoViewer may be installed via SPM, by pointing at this repo's URL.

Cocoapods

NYTPhotoViewer is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'NYTPhotoViewer'

Carthage

NYTPhotoViewer may be installed via Carthage. To install it, simply add the following line to your Cartfile:

github "NYTimes/NYTPhotoViewer"

Then, following the instructions for integrating Carthage frameworks into your app, link the NYTPhotoViewer and PINRemoteImage frameworks into your project.

If you don't want support for animated GIFs, you may instead link against only the NYTPhotoViewerCore framework.

Requirements

This library requires a deployment target of iOS 9.0 or greater.

Changelog

See CHANGELOG.md.

Contributing

Please open pull requests against the develop branch, and add a relevant note to the develop section of the CHANGELOG as part of your pull request.

Swift

NYTPhotoViewer is written in Objective-C but is fully interoperable with Swift. If you experience any interoperability difficulties, please open an issue or pull request and we will work to resolve it.

Inspiration

NYTPhotoViewer draws feature inspiration from Facebook and Tweetbot’s image viewers. If this implementation isn’t to your liking, you may consider JTSImageViewController or IDMPhotoBrowser.

Implementation

NYTPhotoViewer has a straightforward implementation using standard UIKit components. The viewer is a UIViewController and uses UIViewController transitioning APIs for the animated and interactive transitions, a UIPageViewController for horizontal swiping between images, and UIScrollView for image zooming.

It is intended to be used without the need for subclassing, and as such it accepts model objects conforming to a NYTPhoto protocol and provides ample opportunity for customization via the NYTPhotosViewControllerDelegate. Since standard APIs are used, the client has full control over the transitions and customization of the NYTPhotosViewController.

License

NYTPhotoViewer is available under the Apache 2.0 license. See LICENSE.md for more information.

Contributors

A list of contributors is available through GitHub.

nytphotoviewer's People

Contributors

alexbrashear avatar atecle avatar bcapps avatar cdzombak avatar craighowarth avatar dagogatc avatar davbeck avatar dependabot[bot] avatar dzlobin avatar genius-munou avatar grantjbutler avatar heikkihautala avatar jamesstout avatar kant avatar kimar avatar krzysztofzablocki avatar lrossi avatar mattbischoff avatar meta2 avatar mpkeefe avatar mr-fixit avatar noremac avatar ondrejhanak avatar osvaldonytimes avatar petarbelokonski avatar prayagverma avatar steve-matthews avatar twigz avatar yorkepb avatar zeveisenberg 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  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

nytphotoviewer's Issues

completionHandler deprecated

In NYTPhotosViewController.m, this line:

activityViewController.completionHandler = ^(NSString *activityType, BOOL completed) {

throws this warning:

'completionHandler' is deprecated: first deprecated in iOS 8.0 - Use completionWithItemsHandler instead.

Because of this, from UIActivityViewController.h:

@property(nonatomic,copy) UIActivityViewControllerCompletionHandler completionHandler NS_DEPRECATED_IOS(6_0, 8_0, "Use completionWithItemsHandler instead.");  // set to nil after call
@property(nonatomic,copy) UIActivityViewControllerCompletionWithItemsHandler completionWithItemsHandler NS_AVAILABLE_IOS(8_0); // set to nil after call

Image Loading

There seems to be a problem with the way this library loads images from its resources bundle.

From the looks of it you guys are using [UIImage imageNamed:] in NYTPhotosViewController, which searches the main bundle. On my device, that doesn't work, and the image is not loaded. I'm not very familiar with the way Cocoapods works, but it may have something to do with the fact that I'm using use_frameworks! in my podfile.

I think the easiest way to fix this is to use [UIImage imageNamed:inBundle:compatibleWithTraitCollection:] with the bundle received from [NSBundle bundleForClass:], as that will load the image from the appropriate bundle.

Just as a side note, I see you guys are using resources and not resource_bundles in your podspec, and I think the cocoapods team has deprecated resources in favor of resource_bundles.

Thanks in advance for replies 👍

initWithPhotos:initialPhoto does not add zoom and scale gestures

If you use initWithPhotos:initialPhoto the initial photo does not have pinch zoom or double tap zoom capabilities. I believe this is because no delegate is set when (NYTPhotoViewController *)newPhotoViewControllerForPhoto:(id <NYTPhoto>)photo is invoked.

Work around is to just use initWithPhotos and then set the delegate before displayPhoto:

NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:self.slideShowPhotosArray];
photosViewController.delegate = self;
[photosViewController displayPhoto:[self.slideShowPhotosArray objectAtIndex:index] animated:NO];

Close Button Missing

Steps to Reproduce

  1. Run either of the sample projects.
  2. Tap the photo.

Expected Results

An “X” button called NYTPhotoViewerCloseButtonX is displayed in the upper left corner of the view controller.

Actual Results

No “X” button is displayed and the nyt_photoViewerResourceBundle method returns nil.

Platform and OS

Tested both Swift 2 (with minor changes to get it to compile) and Objective-C sample projects as well as another project.

Xcode Version 7.2 (7C68)

updateImagesOnPhotosViewController not loading

Hi,

I am trying to call updateImagesOnPhotosViewController but the first time I load the NYTPhotosViewController VC the images don't load (although the spinner rotates) apart from the one marked in "initialPhoto". If I enter the VC the second time all images are loaded successfully.

Any ideas?


- (void)bigButtonTapped:(NSUInteger)index {

    NSMutableArray *photos = [[NSMutableArray alloc] initWithCapacity:_images.count];
    for(int i=0; i < _images.count; i++) {
        NYTExamplePhoto *tempImage = [[NYTExamplePhoto alloc] init];
        tempImage.image = nil;
        [photos addObject:tempImage];
    }


    NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:photos initialPhoto:[photos objectAtIndex:index]];
    photosViewController.leftBarButtonItem.tintColor = [UIColor whiteColor];
    [self presentViewController:photosViewController animated:YES completion:nil];
    photosViewController.delegate = self;

    [self updateImagesOnPhotosViewController:photosViewController afterDelayWithPhotos:photos];


}

// This method simulates previously blank photos loading their images after some time.
- (void)updateImagesOnPhotosViewController:(NYTPhotosViewController *)photosViewController afterDelayWithPhotos:(NSArray *)photos {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        for (NYTExamplePhoto *photo in photos) {
            if (!photo.image) {
                NSString *photoUrl = [_images objectAtIndex:[photos indexOfObject:photo]];
                UIImageView *imageView = [[UIImageView alloc] init];
                [imageView setImageWithURL:[NSURL URLWithString:photoUrl] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];

                photo.image = imageView.image;

                [photosViewController updateImageForPhoto:photo];
            }
        }
    });
}

Zoom to 100% on double tap

On iPhone 5 (at least), when testing with the example project photo, fully zooming in (portrait) takes 3 sets of double taps instead of 2 which I believe was the intention (and is the case in my iPhone 6 Plus testing).

Zoom to 100% on all devices on double tap.

uncaught exception when presenting the view

I pass along an image array like this

#import <NYTPhotosViewController.h>
....
-(void)myfunction{
  NYTPhotosViewController *mySlideShow = [[NYTPhotosViewController alloc]initWithPhotos:self.myImageArray];

 [self presentViewController:mySlideShow animated:YES completion:nil];
}

and now when I run the app and click on the image to present the viewcontroller I get an exception error for an unrecognized selector sent to instance

2015-03-30 12:39:39.491 *my app*[2822:51678] -[UIImage image]: unrecognized selector sent to instance 0x7f9143c8f000
2015-03-30 12:39:39.526 *my app*[2822:51678] *** Terminating app due to uncaught exception     'NSInvalidArgumentException', reason: '-[UIImage image]: unrecognized selector sent to instance 0x7f9143c8f000'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010afc7a75 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010ac60bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010afced1d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010af269dc ___forwarding___ + 988
    4   CoreFoundation                      0x000000010af26578 _CF_forwarding_prep_0 + 120
    5   *my app*                          0x0000000108e166e6 -[NYTPhotoViewController initWithPhoto:loadingView:notificationCenter:] + 246
    6   *my app*                          0x0000000108e1d167 -[NYTPhotosViewController newPhotoViewControllerForPhoto:] + 343
    7   *my app*                          0x0000000108e1aaca -[NYTPhotosViewController setupPageViewControllerWithInitialPhoto:] + 602
    8   *my app*                          0x0000000108e1a785 -[NYTPhotosViewController initWithPhotos:initialPhoto:] + 1589
    9   *my app*                          0x0000000108e1a0f0 -[NYTPhotosViewController initWithPhotos:] + 128
    10  *my app*                         0x0000000108dfec37 -[GSItemDetailViewController NYTImageController] + 135
    11  UIKit                               0x0000000109645a22 -[UIApplication sendAction:to:from:forEvent:] + 75
    12  UIKit                               0x000000010974ce50 -[UIControl _sendActionsForEvents:withEvent:] + 467
    13  UIKit                               0x000000010974c21f -[UIControl touchesEnded:withEvent:] + 522
    14  UIKit                               0x00000001099f3e80 _UIGestureRecognizerUpdate + 9487
    15  UIKit                               0x000000010968b856 -[UIWindow _sendGesturesForEvent:] + 1041
    16  UIKit                               0x000000010968c483 -[UIWindow sendEvent:] + 667
    17  UIKit                               0x0000000109658fb1 -[UIApplication sendEvent:] + 246
    18  UIKit                               0x0000000109666227 _UIApplicationHandleEventFromQueueEvent + 17700
    19  UIKit                               0x000000010964123c _UIApplicationHandleEventQueue + 2066
    20  CoreFoundation                      0x000000010aefcc91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    21  CoreFoundation                      0x000000010aef2b5d __CFRunLoopDoSources0 + 269
    22  CoreFoundation                      0x000000010aef2194 __CFRunLoopRun + 868
    23  CoreFoundation                      0x000000010aef1bc6 CFRunLoopRunSpecific + 470
    24  GraphicsServices                    0x000000010cf8fa58 GSEventRunModal + 161
    25  UIKit                               0x0000000109644580 UIApplicationMain + 1282
    26  *my app*                          0x0000000108df7673 main + 115
    27  libdyld.dylib                       0x000000010c4e2145 start + 1
   28  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Crash Upon Rotating Photo Viewer on iOS 7

2015-03-03 16:26:34.950 NYTPhotoViewer[7582:613] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. NYTPhotosOverlayView's implementation of -layoutSubviews needs to call super.'

We are calling super in that layoutSubviews.

Delegate methods are not called for first photo

(title was: "Initial photo doesn't support custom loading view or maximum zoom scale")

on develop, delegate calls looking for a loading view and for a customized maximum zoom scale won't be made for the initial photo.

This has to do with the delegate not being assigned until after the initializer completes; as part of that process the PhotosViewController tries, and fails, to ask the delegate for this information. Fixing will require setting a delegate in the initializer, or deferring some amount of setup until after initialization.

Additional links & discussion

The default implementation for sharing a photodoesn’t work with Facebook & Twitter.

The default implementation for sharing a photo (in NYTPhotosViewController - actionButtonTapped), doesn’t work with Facebook & Twitter. The image is not shown in the share dialog and the "post" button remains disabled.

This is because the activity items passed to UIActivityViewController’s constructor (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIActivityViewController_Class/#//apple_ref/occ/instm/UIActivityViewController/initWithActivityItems:applicationActivities:) must adopt UIActivityItemSource protocol. Currently a UIImage instance is passed as an activity item. UIImage does not adopt this protocol.

The share action can be handled manually ( by implementing photosViewController:handleActionButtonTappedForPhoto: ), but still the default implementation should also work.

PhotosViewController instances cannot be reused

The following gif demonstrates what happens when you try to keep a reference to the photos VC around:

photos VC presentation issue

This was on @mpkeefe's Swift example branch before he resolved it via aa27285 .

This hints to me that something doesn't get reset properly after the VC is dismissed, and the VC is in a bad state if you try to present it again.

Holding on to and reusing a view controller is perfectly reasonable, even if most of the time a VC is presented only once.

Add presenter independent interface orientation support

NYTPhotosViewController inherits the supported interface orientations from the presenter, because the modal presentation style is set to UIModalPresentationStyleCustom.

My presenter view controller only supports portrait mode, but I would like to support landscape on the NYTPhotosViewController.

I have set NYTPhotosViewController's presentation style to the default value (UIModalPresentationStyleFullscreen) after the initialization to support other orientations too, but this breaks at least the interactive fade animations when UIPhotosViewController is closed by swiping the view up or down.

Dismiss function public

It would be great if we could make the dismiss function public to that the viewcontroller can be removed through custom logic. An option would be to access the done button method.

- (void)doneButtonTapped:(id)sender {
    self.transitionController.forcesNonInteractiveDismissal = YES;
    [self setOverlayViewHidden:YES animated:NO];
    [self dismissAnimated:YES];
}

Close button not showing

I am using the latest version of NYT and everything is working absolutely fine except the close button is hidden since I switched to cocoapods use_frameworks. Does anyone have any idea how to solve this issue?

Thanks :)

EDIT: Seems to be related to this issue: #64
I'm using cocoapods and use_frameworks as well.

Presentation animation flickers on iPad

Hi,

thank you for this great library, the API is so well designed and documented, that integrating it in our application was a pleasure :)!

We've noticed a tiny flickering when you run an app that only supports iPhone on an iPad.

Steps to reproduce the bug:

  • Change Deployment Info -> Devices from Universal to iPhone
  • Run the example project on an iPad (or iPad Simulator)
  • Tap on the photo
  • You'll notice a flickering while the animation is running

Cheers,
plu

Translation of NSLocalizedString(@"%lu of %lu", nil)

Locally I have subclassed this AWESOME NYTPhotosViewController and overridden the method "updateOverlayInformation". But I could do a PR so we could localize this in different languages?

Again, hell of a job you have done here. With my two hands, three thumbs up 👍 👍 👍

Related:
image

Animated GIF support

Are you planning to add animated GIF support?

If not: Would you potentially be interested in having this in? For us this is definitely a requirement and I'd be keen to implement this and create a PR.

Cheers,
Marcus

The size and the orientation of the NYTPhotosViewController is wrong on iOS7 when presented from a formsheet

This issue is present on the master branch.
When the NYTPhotosViewController is presented from a formsheet viewcontroller, the size and the orientation are wrong.
As you can see from the screenshot, the final size is the size of the presenting viewcontroller. And if the NYTPhotosViewController in landscape the orientation is still portrait.

form_sheet
presented

I created a sample project to demonstrate the issue here: https://github.com/ignazioc/NYTPhotoViewer/tree/ios7_testing

UIScrollView instead of UILabel in PhotoCaptionView

Is it possible to create a UIScrollView instead of UILabel in photo captions ?

When captions are too long it seems ugly in screen.

ios simulator screen shot apr 12 2015 10 14 50 pm

Instead of UILabel I think it will be good to create that label in scrollview like facebook does.

If the label has more than our pre defined lines (for example 5 lines) it will be converted to scrollview.

Crash on iPad when tap share button

Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x7c48a5c0>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.'

Any idea about making this library in the whole code with Swift?

I agree.This was a beautifully designed library.But,would u mind creating this project for Swift User in Swift code?Because I don't know Obj-C code.I want to learn your library which was exactly in pinch and zoom feature and gesture function.

So,Thanks for your hard work!!!
Any help with Swift Version,Thank you,Sir.

Swift Sample Project Does Not Compile

As mentioned in #102.

Steps to Reproduce

  1. Clone the project.
  2. Attempt to run the Swift sample application target.

Expected Results

The app runs.

Actual Results

The app fails to build with a number of errors.

Platform and OS

Xcode Version 7.2 (7C68)

Intermittent "Glitchy" Captions When Swiping Between Photos

On my iPhone 6 Plus while testing in newsreader, I've intermittently seen the text below the photo in a slideshow appear glitchy (jumping from being aligned at the bottom to above that position quickly back and forth) when swiping between the first and second photo. It's inconsistent, and not definitive, but I've only seen this happen after scrolling the article before tapping the slideshow.

Change Copyright

+// Copyright (c) 2015 Brian Capps. All rights reserved.

to

+// Copyright (c) 2015 NYTimes. All rights reserved.

photoloader

can you plz make the ability to asyncro. load the images and show a progress bar while loading the image

Landscape orientation

If viewcontroller that present NYTPhotosViewController not support Landscape orientation NYTPhotosViewController not support it too.
But what if i want rotate photo?

support rotation separate from presenting view

It seems like the orientations supported when presented matches the set orientations on the presenting view. Is there a way, or could you add a way, so that the photos viewer can be rotated even if the presenting view can't?

Swiping Prevented on iPhone 6 Plus After Zooming In and Out

On 6 Plus, zooming in via 2 finger gesture or double tap, and then zooming out (either way) prevents the ability to swipe horizontally to another photo or vertically to dismiss. This doesn't occur every time, but is very easily reproducible on device.

Update Overlay Information Earlier

When swiping between photos, the captions don't change until the transition from one photo to another completes. Though not as straight forward from a coding perspective, it'd be nice if the information would update halfway through the transition so that the captions always apply to the photo that is occupying most of the screen.

NYTPhotosViewController crashes on tapping Share button on iPad

I made a sample app (PRs: #25 #27) in Swift that mimics the current example ObjC app and runs on both iPhone and iPad, using the built-in NYTPhotosViewController. On iPad, the ShareActivityViewController crashes because it needs to be presented inside a popover. This can be done in iOS 8 simply by setting shareActivityViewController.popoverPresentationController?.barButtonItem but on iOS 7 will need to wrap inside a UIPopoverController I guess. Are there any other considerations?

Example app doesn't start up under iOS 7

Looks like a problem with the asset catalog.

Console:
2015-03-30 22:14:42.422 NYTPhotoViewer[17453:607] Unable to create unsliced image from csi bitmap data.
2015-03-30 22:14:42.438 NYTPhotoViewer[17453:607] Could not load the "NYTimesBuilding" image referenced from a nib in the bundle with identifier "org.cocoapods.demo.NYTPhotoViewer"

Found this

Add umbrella header

It's unexpected that the following doesn't work:

#import <NYTPhotoViewer/NYTPhotoViewer.h>

It would be great if there was an umbrella header. This will be required for #61 anyway :)

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.