Skip to content

Commit 8ac0c31

Browse files
committed
Added page view spine to highlight how many images there are to swipe through
1 parent 59598fd commit 8ac0c31

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Optik/Classes/AlbumViewController.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ internal final class AlbumViewController: UIViewController {
9191
self.toolbar?.alpha = 1.0
9292
self.toolbar?.transform = CGAffineTransformIdentity
9393
}
94+
95+
let scale = (self.pageViewController.view.bounds.height
96+
- (self.navigationBarHidden ? CGFloat(0) : Constants.navbarHeight)
97+
- (self.toolbarHidden ? CGFloat(0) : Constants.toolbarHeight)) / self.view.bounds.height
98+
self.pageViewController.view.transform = CGAffineTransformMakeScale(scale, scale)
9499
})
95100
}
96101
}
@@ -146,6 +151,9 @@ internal final class AlbumViewController: UIViewController {
146151

147152
override func viewWillAppear(animated: Bool) {
148153
super.viewWillAppear(animated)
154+
155+
navigationBarHidden = false
156+
toolbarHidden = false
149157

150158
// HACK: UIKit doesn't animate status bar transition on iOS 9. So, manually animate it.
151159
if !viewDidAppear {
@@ -193,6 +201,7 @@ internal final class AlbumViewController: UIViewController {
193201
private func setupPageViewController() {
194202
pageViewController.dataSource = self
195203
pageViewController.delegate = self
204+
pageViewController.view.clipsToBounds = false
196205

197206
// Set up initial image view controller.
198207
if let imageViewController = imageViewController(forIndex: initialImageDisplayIndex) {
@@ -376,5 +385,26 @@ extension AlbumViewController: UIPageViewControllerDelegate {
376385
imageViewerDelegate?.imageViewerDidDisplayImage(atIndex: currentImageIndex)
377386
}
378387
}
388+
389+
func pageViewController(pageViewController: UIPageViewController, spineLocationForInterfaceOrientation orientation: UIInterfaceOrientation) -> UIPageViewControllerSpineLocation {
390+
return .Max
391+
}
392+
393+
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
394+
return numberOfImages()
395+
}
396+
397+
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
398+
return currentImageViewController?.index ?? 0
399+
}
400+
401+
private func numberOfImages() -> Int {
402+
switch imageData {
403+
case .Local(images: let images):
404+
return images.count
405+
case .Remote(urls: let urls, imageDownloader: _):
406+
return urls.count
407+
}
408+
}
379409

380410
}

0 commit comments

Comments
 (0)