@@ -12,6 +12,7 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
12
12
13
13
/// UI
14
14
private var closeButton : UIButton ?
15
+ private var seeAllButton : UIButton ?
15
16
/// You can set any UIView subclass here. If set, it will be integrated into view hierachy and laid out
16
17
/// following either the default pinning settings or settings from a custom configuration.
17
18
public var headerView : UIView ?
@@ -47,7 +48,8 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
47
48
private let toggleHeaderFooterAnimationDuration = 0.15
48
49
private let closeAnimationDuration = 0.2
49
50
private let rotationAnimationDuration = 0.2
50
- private var closeLayout = CloseButtonLayout . PinRight ( 25 , 16 )
51
+ private var closeLayout = ButtonLayout . PinLeft ( 8 , 16 )
52
+ private var seeAllLayout = ButtonLayout . PinRight ( 8 , 16 )
51
53
private var headerLayout = HeaderLayout . Center ( 25 )
52
54
private var footerLayout = FooterLayout . Center ( 25 )
53
55
private var statusBarHidden = true
@@ -92,10 +94,12 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
92
94
case . SpinnerStyle( let style) : spinnerStyle = style
93
95
case . SpinnerColor( let color) : spinnerColor = color
94
96
case . CloseButton( let button) : closeButton = button
97
+ case . SeeAllButton( let button) : seeAllButton = button
95
98
case . PagingMode( let mode) : galleryPagingMode = mode
96
99
case . HeaderViewLayout( let layout) : headerLayout = layout
97
100
case . FooterViewLayout( let layout) : footerLayout = layout
98
101
case . CloseLayout( let layout) : closeLayout = layout
102
+ case . SeeAllLayout( let layout) : seeAllLayout = layout
99
103
case . StatusBarHidden( let hidden) : statusBarHidden = hidden
100
104
case . HideDecorationViewsOnLaunch( let hidden) : isDecorationViewsHidden = hidden
101
105
case . BackgroundColor( let color) : backgroundColor = color
@@ -180,7 +184,7 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
180
184
181
185
func configureInitialImageController( ) {
182
186
183
- let initialImageController = ImageViewController ( imageProvider : imageProvider , configuration : configuration , imageCount : imageCount , displacedView : displacedView , startIndex: startIndex , imageIndex : startIndex , showDisplacedImage : true , fadeInHandler : fadeInHandler , delegate : self )
187
+ let initialImageController = self . imageControllerFactory . createImageViewController ( startIndex)
184
188
self . setViewControllers ( [ initialImageController] , direction: UIPageViewControllerNavigationDirection . Forward, animated: false , completion: nil )
185
189
initialImageController. view. hidden = true
186
190
@@ -195,13 +199,21 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
195
199
196
200
closeButton? . addTarget ( self , action: #selector( GalleryViewController . interactiveClose) , forControlEvents: . TouchUpInside)
197
201
}
198
-
202
+
203
+ private func configureSeeAllButton( ) {
204
+
205
+ seeAllButton? . addTarget ( self , action: #selector( GalleryViewController . seeAll) , forControlEvents: . TouchUpInside)
206
+ }
207
+
199
208
func createViewHierarchy( ) {
200
209
201
210
if let close = closeButton {
202
-
203
211
self . view. addSubview ( close)
204
212
}
213
+
214
+ if let seeAllButton = seeAllButton {
215
+ self . view. addSubview ( seeAllButton)
216
+ }
205
217
}
206
218
207
219
func configureHeaderView( ) {
@@ -223,6 +235,7 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
223
235
self . presentTransition. headerView = self . headerView
224
236
self . presentTransition. footerView = self . footerView
225
237
self . presentTransition. closeView = self . closeButton
238
+ self . presentTransition. seeAllView = self . seeAllButton
226
239
}
227
240
228
241
public override func viewDidLoad( ) {
@@ -231,6 +244,7 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
231
244
configureHeaderView ( )
232
245
configureFooterView ( )
233
246
configureCloseButton ( )
247
+ configureSeeAllButton ( )
234
248
configurePresentTransition ( )
235
249
createViewHierarchy ( )
236
250
}
@@ -241,6 +255,7 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
241
255
super. viewDidLayoutSubviews ( )
242
256
243
257
layoutCloseButton ( )
258
+ layoutSeeAll ( )
244
259
layoutHeaderView ( )
245
260
layoutFooterView ( )
246
261
}
@@ -264,7 +279,23 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
264
279
close. frame. origin. y = marginTop
265
280
}
266
281
}
267
-
282
+
283
+ func layoutSeeAll( ) {
284
+
285
+ guard let seeAllButton = seeAllButton else { return }
286
+
287
+ switch seeAllLayout {
288
+ case . PinRight( let marginTop, let marginRight) :
289
+ seeAllButton. autoresizingMask = [ . FlexibleBottomMargin, . FlexibleLeftMargin]
290
+ seeAllButton. frame. origin. x = self . view. bounds. size. width - marginRight - seeAllButton. bounds. size. width
291
+ seeAllButton. frame. origin. y = marginTop
292
+ case . PinLeft( let marginTop, let marginLeft) :
293
+ seeAllButton. autoresizingMask = [ . FlexibleBottomMargin, . FlexibleRightMargin]
294
+ seeAllButton. frame. origin. x = marginLeft
295
+ seeAllButton. frame. origin. y = marginTop
296
+ }
297
+ }
298
+
268
299
func layoutHeaderView( ) {
269
300
270
301
guard let header = headerView else { return }
@@ -349,14 +380,52 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
349
380
350
381
closeWithAnimation ( closedCompletion)
351
382
}
352
-
383
+
384
+ func seeAll( ) {
385
+ let seeAllController = ThumbnailsViewController ( imageProvider: self . imageProvider)
386
+ let closeButton = UIButton ( frame: CGRect ( origin: CGPoint . zero, size: CGSize ( width: 50 , height: 50 ) ) )
387
+ closeButton. setImage ( UIImage ( named: " close_normal " ) , forState: UIControlState . Normal)
388
+ closeButton. setImage ( UIImage ( named: " close_highlighted " ) , forState: UIControlState . Highlighted)
389
+ seeAllController. closeButton = closeButton
390
+ seeAllController. closeLayout = closeLayout
391
+ seeAllController. onItemSelected = { index in
392
+ self . goToIndex ( index)
393
+ }
394
+ presentViewController ( seeAllController, animated: true , completion: nil )
395
+ }
396
+
397
+ public func goToIndex( index: Int ) {
398
+ guard currentIndex != index && index >= 0 && index < imageCount else { return }
399
+
400
+ let imageViewController = self . imageControllerFactory. createImageViewController ( index)
401
+ let direction : UIPageViewControllerNavigationDirection = index > currentIndex ? . Forward : . Reverse
402
+
403
+ // workaround to make UIPageViewController happy
404
+ if direction == . Forward {
405
+ let previousVC = self . imageControllerFactory. createImageViewController ( index - 1 )
406
+ setViewControllers ( [ previousVC] , direction: direction, animated: true , completion: { finished in
407
+ dispatch_async ( dispatch_get_main_queue ( ) , { [ weak self] in
408
+ self ? . setViewControllers ( [ imageViewController] , direction: direction, animated: false , completion: nil )
409
+ } )
410
+ } )
411
+ } else {
412
+ let nextVC = self . imageControllerFactory. createImageViewController ( index + 1 )
413
+ setViewControllers ( [ nextVC] , direction: direction, animated: true , completion: { finished in
414
+ dispatch_async ( dispatch_get_main_queue ( ) , { [ weak self] in
415
+ self ? . setViewControllers ( [ imageViewController] , direction: direction, animated: false , completion: nil )
416
+ } )
417
+ } )
418
+ }
419
+ }
420
+
353
421
func closeWithAnimation( completion: ( ( ) -> Void ) ? ) {
354
422
355
423
UIView . animateWithDuration ( 0.1 , animations: { [ weak self] in
356
424
357
425
self ? . headerView? . alpha = 0.0
358
426
self ? . footerView? . alpha = 0.0
359
427
self ? . closeButton? . alpha = 0.0
428
+ self ? . seeAllButton? . alpha = 0.0
360
429
361
430
} ) { [ weak self] done in
362
431
@@ -399,6 +468,7 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
399
468
let alpha = 1 - distance * swipeToDismissFadeOutAccelerationFactor
400
469
401
470
closeButton? . alpha = alpha
471
+ seeAllButton? . alpha = alpha
402
472
headerView? . alpha = alpha
403
473
footerView? . alpha = alpha
404
474
}
@@ -415,7 +485,7 @@ final public class GalleryViewController : UIPageViewController, UIViewControlle
415
485
self ? . headerView? . alpha = alpha
416
486
self ? . footerView? . alpha = alpha
417
487
self ? . closeButton? . alpha = alpha
418
-
488
+ self ? . seeAllButton ? . alpha = alpha
419
489
} )
420
490
}
421
491
0 commit comments