• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    Objective-C
  • License
    Apache License 2.0
  • Created about 12 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

iOS project which closely mimics the behavior of the Apple Photos app

PhotoZoom

iOS project which closely mimics the behavior of the Apple Photos app.

Overview

There are lots of photo browsing projects. You can find some on Cocoa Controls but I did not find them to met my needs. I wanted something that is very simple which could be dropped into an app easily. This solution is simply an extension of UIScrollView with the addition of tap gestures.

The project was built by referencing the PhotoScroller and AutoScroll samples from Apple. (See @elizablock on Twitter)

View Controller and Views Hierarchy

In this project the hierarchy goes like the following:

PZViewController -> UICollectionView -> PZPhotoView

The PZViewController implements delegate methods to generate the views which are displayed in a collection view. These views are all instances of PZPhotoView and one delegate method handles the configuration of each instance to display an image. It's possible to implement the delegate methods differently to put anything into a paging scroll view. Currently images are generated with a NIB as a palette to keep things self-contained to facilitate testing. Downloading actual images could be done next. This approach avoids loading all of the images at the same time to avoid exessive memory usage. The delegate methods could even handle different kinds of views inside of the paging scroll view.

The tricky parts are going into and out of full screen mode by hiding each of the bars as well as rotation. Logging out the layout from the top down to the bottom views was helpful in seeing what was happening. There seem to be lots of side effects which I do not usually expect so I had to observe and respond to them. More work needs to be done to ensure these hacks can be made more reliable across future releases and potentially make it compatible with iOS 5 which has not been tested at all.

Approach

I could have put more of the code into view controllers but I am finding that coding inside of views to work better along with delegates to handle anything which is unique so it is easier to reuse and extend. This way I can drop multiple views into a parent view and get all of the functionality without any trouble. It's possible there could be multiple paging scroll views managed inside a view controller like an a news app like Pulse. This paging scroll view could be placed into a NIB managed inside of a Storyboard and just set the base class to align it with your own inherited version of the view which can implement delegate methods as you need them.

Reuse

To use these classes in your own project you only need PZPhotoView and a collection view. The rest is just for reference on how it should work.

CocoaPods

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

pod "PhotoZoom"

or

platform :ios, "7.0"
pod 'PhotoZoom', :git => 'https://github.com/brennanMKE/PhotoZoom.git', :tag => '0.0.2'

Caveats

The geometry can be tricky when managing a scroll view within a scroll view. Then there is the process of hiding and showing the status bar, navbar and toolbar which can distort the layout and require observing those changes and adapting with by coding adaptations or to better manage the layout with autoresizing. I found it very difficult to toggle full screen mode due to the side effects to the layout. I tried to mimic the behavior in the Photos app but from the public API I do not seem to have a safe way to animate the status bar and other bars in sync with each other. So I have simply done the best that I can do. There is a jump due to the status bar which I would prefer to eliminate once I can learn a better approach. Once I get some answers on the developer forums or Stackoverflow I may be able to update this code to provide a smoother transition.

Quirks

Something odd about this project is the fact that the NavigationBar does not show by default. I have to make it visible with code. That does not make sense as it should show by default. I need to learn why that is happening and fix it. It may simply be a bug with Xcode with the frequence changes to Interface Builder recently and it will work itself out automatically.

Brennan Stehling
SmallSharpTools LLC
www.smallsharptools.com

More Repositories

1

MultipleTargets

Building multiple iOS apps from a single project using multiple targets
Objective-C
49
star
2

ADNActivityCollection

UIActivities to share with App.net (ADN) apps from an Activity Sheet
Objective-C
37
star
3

OptimizedNetworking

iOS project to show how to use NSOperationQueue for optimal networking.
Objective-C
19
star
4

CircleButton

Easy way to create buttons masked in a circle with colored border without the anti-aliasing distortion
Objective-C
17
star
5

Interfaces

Interfaces for iOS (experiments in UI/UX components)
Objective-C
14
star
6

mixpanel-parse

Mixpanel for Parse Cloud Code
JavaScript
10
star
7

FlatButtons

Flat Buttons for iOS 7
Objective-C
10
star
8

BitlyForiOS

URL Shortener using Bitly with AFNetworking
Objective-C
9
star
9

BottomTable

Sample project which has the content in a table view settle on the bottom.
Objective-C
8
star
10

SSTTapSlider

Tap Slider which updates UISlider to add tap and pan gesture behavior
Objective-C
7
star
11

Speakerbox

Speakerbox updated with iOS 9 as the baseline version.
C++
5
star
12

GlossyButtons

Buttons drawn with Quartz to appear glossy like the buttons in Apple apps
5
star
13

OverTheAir

Automatic update for Over the Air deployment files using a Swift script.
Swift
2
star
14

PostThings

Sample app for working with Parse
JavaScript
2
star
15

StaticLibraryForXcode4AndiOS

Static Library for Xcode 4 and iOS
Objective-C
2
star
16

TestServer

Test Server with Swifter
Swift
1
star
17

BlurredMenu

Technique to display a menu with the contents behind it blurred.
Objective-C
1
star
18

TableMadness

A sample project which shows how to add and remove rows from a UITableView in iOS
Objective-C
1
star
19

SharingActivity

Sample project showing how to stop and start an activity while showing the activities modal.
Swift
1
star
20

DrawingRoundedCorners

Examples of drawing various shapes with code
Objective-C
1
star