123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- public typealias NCViewerImageContentTransformer = (_ contentView: UIView, _ position: CGFloat) -> Void
- public enum NCViewerImageDefaultContentTransformers {
-
- public static let horizontalMoveInOut: NCViewerImageContentTransformer = { contentView, position in
- let widthIncludingGap = contentView.bounds.size.width + NCViewerImageContentView.interItemSpacing
- contentView.transform = CGAffineTransform(translationX: widthIncludingGap * position, y: 0.0)
- }
-
- public static let verticalMoveInOut: NCViewerImageContentTransformer = { contentView, position in
- let heightIncludingGap = contentView.bounds.size.height + NCViewerImageContentView.interItemSpacing
- contentView.transform = CGAffineTransform(translationX: 0.0, y: heightIncludingGap * position)
- }
-
- public static let horizontalSlideOut: NCViewerImageContentTransformer = { contentView, position in
- var scale: CGFloat = 1.0
- if position < -0.5 {
- scale = 0.9
- } else if -0.5...0.0 ~= Double(position) {
- scale = 1.0 + (position * 0.2)
- }
- var transform = CGAffineTransform(scaleX: scale, y: scale)
- let widthIncludingGap = contentView.bounds.size.width + NCViewerImageContentView.interItemSpacing
- let x = position >= 0.0 ? widthIncludingGap * position : 0.0
- transform = transform.translatedBy(x: x, y: 0.0)
- contentView.transform = transform
- let margin: CGFloat = 0.0000001
- contentView.isHidden = ((1.0-margin)...(1.0+margin) ~= abs(position))
- }
-
- public static let verticalSlideOut: NCViewerImageContentTransformer = { contentView, position in
- var scale: CGFloat = 1.0
- if position < -0.5 {
- scale = 0.9
- } else if -0.5...0.0 ~= Double(position) {
- scale = 1.0 + (position * 0.2)
- }
- var transform = CGAffineTransform(scaleX: scale, y: scale)
- let heightIncludingGap = contentView.bounds.size.height + NCViewerImageContentView.interItemSpacing
- let y = position >= 0.0 ? heightIncludingGap * position : 0.0
- transform = transform.translatedBy(x: 0.0, y: y)
- contentView.transform = transform
- let margin: CGFloat = 0.0000001
- contentView.isHidden = ((1.0-margin)...(1.0+margin) ~= abs(position))
- }
-
- public static let horizontalSlideIn: NCViewerImageContentTransformer = { contentView, position in
- var scale: CGFloat = 1.0
- if position > 0.5 {
- scale = 0.9
- } else if 0.0...0.5 ~= Double(position) {
- scale = 1.0 - (position * 0.2)
- }
- var transform = CGAffineTransform(scaleX: scale, y: scale)
- let widthIncludingGap = contentView.bounds.size.width + NCViewerImageContentView.interItemSpacing
- let x = position > 0.0 ? 0.0 : widthIncludingGap * position
- transform = transform.translatedBy(x: x, y: 0.0)
- contentView.transform = transform
- let margin: CGFloat = 0.0000001
- contentView.isHidden = ((1.0-margin)...(1.0+margin) ~= abs(position))
- }
-
- public static let verticalSlideIn: NCViewerImageContentTransformer = { contentView, position in
- var scale: CGFloat = 1.0
- if position > 0.5 {
- scale = 0.9
- } else if 0.0...0.5 ~= Double(position) {
- scale = 1.0 - (position * 0.2)
- }
- var transform = CGAffineTransform(scaleX: scale, y: scale)
- let heightIncludingGap = contentView.bounds.size.height + NCViewerImageContentView.interItemSpacing
- let y = position > 0.0 ? 0.0 : heightIncludingGap * position
- transform = transform.translatedBy(x: 0.0, y: y)
- contentView.transform = transform
- let margin: CGFloat = 0.0000001
- contentView.isHidden = ((1.0-margin)...(1.0+margin) ~= abs(position))
- }
-
- public static let horizontalZoomInOut: NCViewerImageContentTransformer = { contentView, position in
- let minScale: CGFloat = 0.5
-
- let scaleFactor: CGFloat = 0.5
- var scale: CGFloat = CGFloat.maximum(minScale, 1.0 - abs(position * scaleFactor))
-
- let actualGap = contentView.bounds.size.width * scaleFactor * 0.5
- let gapCorrector = NCViewerImageContentView.interItemSpacing - actualGap
- let widthIncludingGap = contentView.bounds.size.width + gapCorrector
- let translation = (widthIncludingGap * position)/scale
- var transform = CGAffineTransform(scaleX: scale, y: scale)
- transform = transform.translatedBy(x: translation, y: 0.0)
- contentView.transform = transform
- }
-
- public static let verticalZoomInOut: NCViewerImageContentTransformer = { contentView, position in
- let minScale: CGFloat = 0.5
-
- let scaleFactor: CGFloat = 0.5
- let scale: CGFloat = CGFloat.maximum(minScale, 1.0 - abs(position * scaleFactor))
-
- let actualGap = contentView.bounds.size.height * scaleFactor * 0.5
- let gapCorrector = NCViewerImageContentView.interItemSpacing - actualGap
- let heightIncludingGap = contentView.bounds.size.height + gapCorrector
- let translation = (heightIncludingGap * position)/scale
- var transform = CGAffineTransform(scaleX: scale, y: scale)
- transform = transform.translatedBy(x: 0.0, y: translation)
- contentView.transform = transform
- }
- }
|