Skip to content

Commit 0f2a821

Browse files
committed
add impl from ObjC & init CI
1 parent 68b5a6d commit 0f2a821

File tree

11 files changed

+279
-17
lines changed

11 files changed

+279
-17
lines changed

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fastlane/* linguist-vendored
2+
*.rb linguist-vendored
3+
Podfile* linguist-vendored
4+
Gemfile* linguist-vendored
5+
Brewfile* linguist-vendored
6+
*.podspec linguist-vendored

.swiftlint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
line_length: 200
2+
file_length: 500

.travis.yml

100755100644
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
osx_image: xcode8.1
1+
osx_image: xcode8.2
22
language: objective-c
33
cache:
44
- bundler
@@ -11,8 +11,9 @@ notifications:
1111
email: false
1212
before_install:
1313
- gem install bundler
14-
- brew update
14+
- bundle update && brew update
1515
- bundle install && brew bundle
16+
- bundle exec pod repo update --silent
1617
script:
1718
- bundle exec fastlane run_tests
1819
after_success:

Samples/DGParallaxInteractiveTransitionSample-iOS/DGParallaxInteractiveTransitionSample-iOS.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
A30D640B1E0D71CB00A3CE45 /* DGParallaxInteractiveTransition.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A30D64091E0D71CB00A3CE45 /* DGParallaxInteractiveTransition.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1616
A30D640F1E0D73B300A3CE45 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A30D640D1E0D73B300A3CE45 /* ViewController.swift */; };
1717
A30D64101E0D73B300A3CE45 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A30D640E1E0D73B300A3CE45 /* ViewController.xib */; };
18+
A3AB9D5F1E3250EC005040F7 /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3AB9D5D1E3250EC005040F7 /* DetailViewController.swift */; };
19+
A3AB9D601E3250EC005040F7 /* DetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A3AB9D5E1E3250EC005040F7 /* DetailViewController.xib */; };
1820
/* End PBXBuildFile section */
1921

2022
/* Begin PBXCopyFilesBuildPhase section */
@@ -46,6 +48,8 @@
4648
A30D64091E0D71CB00A3CE45 /* DGParallaxInteractiveTransition.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DGParallaxInteractiveTransition.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4749
A30D640D1E0D73B300A3CE45 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
4850
A30D640E1E0D73B300A3CE45 /* ViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ViewController.xib; sourceTree = "<group>"; };
51+
A3AB9D5D1E3250EC005040F7 /* DetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DetailViewController.swift; sourceTree = "<group>"; };
52+
A3AB9D5E1E3250EC005040F7 /* DetailViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DetailViewController.xib; sourceTree = "<group>"; };
4953
/* End PBXFileReference section */
5054

5155
/* Begin PBXFrameworksBuildPhase section */
@@ -85,6 +89,8 @@
8589
A30D63F11E0D717E00A3CE45 /* AppDelegate.swift */,
8690
A30D640D1E0D73B300A3CE45 /* ViewController.swift */,
8791
A30D640E1E0D73B300A3CE45 /* ViewController.xib */,
92+
A3AB9D5D1E3250EC005040F7 /* DetailViewController.swift */,
93+
A3AB9D5E1E3250EC005040F7 /* DetailViewController.xib */,
8894
A30D63F81E0D717E00A3CE45 /* Assets.xcassets */,
8995
A30D63FA1E0D717E00A3CE45 /* LaunchScreen.storyboard */,
9096
A30D63FD1E0D717E00A3CE45 /* Info.plist */,
@@ -180,6 +186,7 @@
180186
A30D63FC1E0D717E00A3CE45 /* LaunchScreen.storyboard in Resources */,
181187
A30D64101E0D73B300A3CE45 /* ViewController.xib in Resources */,
182188
A30D63F91E0D717E00A3CE45 /* Assets.xcassets in Resources */,
189+
A3AB9D601E3250EC005040F7 /* DetailViewController.xib in Resources */,
183190
);
184191
runOnlyForDeploymentPostprocessing = 0;
185192
};
@@ -238,6 +245,7 @@
238245
isa = PBXSourcesBuildPhase;
239246
buildActionMask = 2147483647;
240247
files = (
248+
A3AB9D5F1E3250EC005040F7 /* DetailViewController.swift in Sources */,
241249
A30D640F1E0D73B300A3CE45 /* ViewController.swift in Sources */,
242250
A30D63F21E0D717E00A3CE45 /* AppDelegate.swift in Sources */,
243251
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// DetailViewController.swift
3+
// DGParallaxInteractiveTransitionSample-iOS
4+
//
5+
// Created by Benoit BRIATTE on 20/01/2017.
6+
// Copyright © 2017 Digipolitan. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class DetailViewController: UIViewController {
12+
13+
override func viewDidLoad() {
14+
super.viewDidLoad()
15+
16+
// Do any additional setup after loading the view.
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
6+
<dependencies>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10+
</dependencies>
11+
<objects>
12+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="DetailViewController" customModule="DGParallaxInteractiveTransitionSample_iOS" customModuleProvider="target">
13+
<connections>
14+
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
15+
</connections>
16+
</placeholder>
17+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
18+
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
19+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
20+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
21+
<subviews>
22+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="BOTTOM" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4ZX-2i-7f7">
23+
<rect key="frame" x="152" y="646" width="71" height="21"/>
24+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
25+
<nil key="textColor"/>
26+
<nil key="highlightedColor"/>
27+
</label>
28+
</subviews>
29+
<color key="backgroundColor" red="1" green="0.061523099769999999" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
30+
<constraints>
31+
<constraint firstAttribute="bottom" secondItem="4ZX-2i-7f7" secondAttribute="bottom" id="RiZ-iK-KeG"/>
32+
<constraint firstItem="4ZX-2i-7f7" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="hj4-xe-U7V"/>
33+
</constraints>
34+
</view>
35+
</objects>
36+
</document>

Samples/DGParallaxInteractiveTransitionSample-iOS/DGParallaxInteractiveTransitionSample-iOS/ViewController.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,21 @@ import DGParallaxInteractiveTransition
1111

1212
class ViewController: UIViewController {
1313

14+
let transition = DGParallaxViewControllerTransition()
15+
1416
override func viewDidLoad() {
1517
super.viewDidLoad()
16-
let t = TemplateClass()
17-
print(t)
18+
}
19+
20+
override func viewWillAppear(_ animated: Bool) {
21+
print("APPEAR")
22+
}
23+
24+
@IBAction func touchDisplayDetail(_ sender: Any) {
25+
let detailViewController = DetailViewController()
26+
//let navigationController = UINavigationController(rootViewController: detailViewController)
27+
transition.presentedViewInsets = UIEdgeInsets(top: 50, left: 10, bottom: 50, right: 10)
28+
transition.attach(to: detailViewController)
29+
self.present(detailViewController, animated: true, completion: nil)
1830
}
1931
}

Samples/DGParallaxInteractiveTransitionSample-iOS/DGParallaxInteractiveTransitionSample-iOS/ViewController.xib

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
@@ -21,7 +21,18 @@
2121
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
2222
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
2323
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
24+
<subviews>
25+
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="YCU-ft-lXN">
26+
<rect key="frame" x="134" y="151" width="46" height="30"/>
27+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
28+
<state key="normal" title="Button"/>
29+
<connections>
30+
<action selector="touchDisplayDetail:" destination="-1" eventType="touchUpInside" id="21m-Xm-agR"/>
31+
</connections>
32+
</button>
33+
</subviews>
2434
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
35+
<point key="canvasLocation" x="346" y="212"/>
2536
</view>
2637
</objects>
2738
</document>

Sources/DGParallaxPresentationController.swift

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,83 @@ import UIKit
1010

1111
class DGParallaxPresentationController: UIPresentationController {
1212

13+
var containerViewInsets: UIEdgeInsets
14+
15+
var overlayColor: UIColor? {
16+
get {
17+
return self.overlayView.backgroundColor
18+
}
19+
set {
20+
self.overlayView.backgroundColor = newValue != nil ? newValue : .black
21+
}
22+
}
23+
24+
var maximumOverlayAlpha: CGFloat
25+
26+
fileprivate lazy var overlayView: UIView = {
27+
let overlayView = UIView()
28+
overlayView.autoresizingMask = [.flexibleBottomMargin,
29+
.flexibleHeight,
30+
.flexibleLeftMargin,
31+
.flexibleRightMargin,
32+
.flexibleTopMargin,
33+
.flexibleWidth]
34+
return overlayView
35+
}()
36+
37+
override var shouldRemovePresentersView: Bool {
38+
return true
39+
}
40+
41+
override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) {
42+
self.containerViewInsets = .zero
43+
self.maximumOverlayAlpha = 0.7
44+
super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
45+
self.overlayColor = nil
46+
}
47+
48+
override func presentationTransitionWillBegin() {
49+
super.presentationTransitionWillBegin()
50+
guard let containerView = self.containerView, let presentedView = self.presentedView else {
51+
return
52+
}
53+
self.overlayView.frame = containerView.bounds
54+
self.overlayView.alpha = 0
55+
containerView.insertSubview(self.overlayView, belowSubview: presentedView)
56+
self.presentedViewController.transitionCoordinator?.animate(alongsideTransition: { [weak self] _ in
57+
guard let strongSelf = self else {
58+
return
59+
}
60+
strongSelf.overlayView.alpha = strongSelf.maximumOverlayAlpha
61+
}, completion: nil)
62+
}
63+
64+
override func dismissalTransitionWillBegin() {
65+
super.dismissalTransitionWillBegin()
66+
self.presentedViewController.transitionCoordinator?.animate(alongsideTransition: { [weak self] _ in
67+
guard let strongSelf = self else {
68+
return
69+
}
70+
strongSelf.overlayView.alpha = 0
71+
}, completion: nil)
72+
}
73+
74+
override func dismissalTransitionDidEnd(_ completed: Bool) {
75+
super.dismissalTransitionDidEnd(completed)
76+
if completed {
77+
self.overlayView.removeFromSuperview()
78+
}
79+
}
80+
81+
override var frameOfPresentedViewInContainerView: CGRect {
82+
return UIEdgeInsetsInsetRect(super.frameOfPresentedViewInContainerView, self.containerViewInsets)
83+
}
84+
85+
override func containerViewWillLayoutSubviews() {
86+
super.containerViewWillLayoutSubviews()
87+
guard let containerView = self.containerView else {
88+
return
89+
}
90+
self.presentingViewController.view.bounds = containerView.frame
91+
}
1392
}

Sources/DGParallaxViewControllerAnimator.swift

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
import UIKit
1010

1111
public enum DGParallaxViewControllerAnimatorState {
12-
case presenting;
13-
case dismissing;
12+
case presenting
13+
case dismissing
1414
}
1515

16-
class DGParallaxViewControllerAnimator: UIViewControllerAnimatedTransitioning {
16+
class DGParallaxViewControllerAnimator: NSObject, UIViewControllerAnimatedTransitioning {
1717

18-
open var state: DGParallaxViewControllerAnimatorState
19-
open var viewScale: CGFloat
18+
var state: DGParallaxViewControllerAnimatorState
19+
var viewScale: CGFloat
2020

21-
public init(state: DGParallaxViewControllerAnimatorState) {
21+
init(state: DGParallaxViewControllerAnimatorState) {
2222
self.state = state
2323
self.viewScale = 1
2424
}
@@ -28,11 +28,49 @@ class DGParallaxViewControllerAnimator: UIViewControllerAnimatedTransitioning {
2828
}
2929

3030
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
31-
if let fromViewController = transitionContext.viewController(forKey: UITransitionContextFromViewControllerKey),
32-
let toViewController = transitionContext.viewController(forKey: UITransitionContextFromViewControllerKey) {
33-
31+
guard
32+
let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from),
33+
let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to),
34+
let fromView = fromViewController.view,
35+
let toView = toViewController.view
36+
else {
37+
return
38+
}
39+
let containerView = transitionContext.containerView
40+
var finalFrame = CGRect.zero
41+
if self.state == .presenting {
42+
finalFrame = transitionContext.finalFrame(for: toViewController)
43+
toView.frame = finalFrame.offsetBy(dx: 0, dy: finalFrame.maxY)
44+
containerView.addSubview(toView)
45+
} else {
46+
let fromFinalFrame = transitionContext.finalFrame(for: fromViewController)
47+
finalFrame = fromFinalFrame.offsetBy(dx: 0, dy: fromView.frame.maxY)
48+
}
49+
UIView.animate(withDuration: self.transitionDuration(using: transitionContext), delay: 0, options: UIViewAnimationOptions(rawValue: 0), animations: { [weak self] in
50+
guard let strongSelf = self else {
51+
return
52+
}
53+
if strongSelf.state == .presenting {
54+
toView.frame = finalFrame
55+
fromView.transform = CGAffineTransform.scaledBy(.identity)(x: strongSelf.viewScale, y: strongSelf.viewScale)
56+
} else {
57+
fromView.frame = finalFrame
58+
toView.transform = CGAffineTransform.scaledBy(.identity)(x: strongSelf.viewScale, y: strongSelf.viewScale)
59+
}
60+
}) { [weak self] (finished) in
61+
guard let strongSelf = self else {
62+
return
63+
}
64+
let cancelled = transitionContext.transitionWasCancelled
65+
let completed = finished && !cancelled
66+
transitionContext.completeTransition(completed)
67+
if completed {
68+
if strongSelf.state == .presenting {
69+
containerView.insertSubview(fromView, at: 0)
70+
} else {
71+
fromView.removeFromSuperview()
72+
}
73+
}
3474
}
35-
3675
}
37-
3876
}

0 commit comments

Comments
 (0)