This project provides a drop-in image gallery UI component with a simple interface, as well as a full-screen photo viewer with a drag-to-dismis interaction.
This project is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "UCPhotoGallery"
To integrate UCPhotoGallery into your Xcode project using Carthage, specify it in your Cartfile
:
github "UrbanCompass/UCPhotoGallery" "carthage"
- Instantiate a
UCPhotoGalleryViewController
- Add it as a child view controller
- Add its subview to your view
UCPhotoGalleryViewController *galleryVC = [UCPhotoGalleryViewController new];
galleryVC.dataSource = self;
[self addChildViewController:self.galleryVC];
[self.view addSubview:self.galleryVC.view];
See the "Embedded" tab in the sample app (code in GalleryContainerViewController.m
) for a working example.
This option is a little more invovled, but allows you to display non-full-screen images however you would like and smoothly transition to a full-screen gallery.
- Create a
UCPhotoGalleryFullscreenTransitionController
- Implement the
UIViewControllerTransitioningDelegate
protocol, returning the transition controller created in step 1 - When you want to transition to the full-screen gallery, create a
UCPhotoGalleryViewController
, setisFullscreen
toYES
and itstransitioningDelegate
to your view controller, and set itsmodalPresentationStyle
toUIModalPresentationCustom
- Before presenting the full-screen gallery, set the transition controller's
presentFromRect
andtransitionImage
properties.presentFromRect
is the selected image's frame relative to the screen andtransitionImage
is the image itself. - Call
presentViewController:animated:completed:
to present the full-screen gallery controller created in step 3. - When you're ready to transition to your view controller, update the trasition controller to reflect gallery's page changes wi, you'll need to update your images UI to ensure that a smooth transition back is possible. You will need to keepin sync (see
PhotosCollectionViewController.m
in the example project)
See the "Transition" tab in the sample app (code in PhotosCollectionViewController.m
) for a working example.
UCGalleryViewDataSource
has a very simple, one-method interface: imageURLsForGalleryView:
. Simply provide an NSArray
of image URLs and the gallery can do the rest.
UCGalleryViewDelegate
provides a handful of optional functions that allow the delegate to customize the gallery controller and respond to its actions.
UCPhotoGalleryViewController
supports two different ways of displaying images: aspect fit and aspect fill. Aspect fit is the default, but this can be set a) for all images by setting imageScalingMode
to either UCImageScalingModeFit
or UCImageScalingModeFill
b) for individual images by implementing galleryViewController:scalingModeForImageAtIndex:
on your UCGalleryViewDelegate
.
$ git clone https://github.com/UrbanCompass/UCPhotoGallery.git
$ cd UCPhotoGallery
$ open UCPhotoGallery.xcworkspace
Once in Xcode, ensure the target is UCPhotoGalleryExample
, build, and run.
This project is available under the MIT license. See the LICENSE file for more info.