Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feature/transition manager #86

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions DesignerNewsApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
96AF96151A5EAA41003926E2 /* StoriesTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AF96141A5EAA41003926E2 /* StoriesTableViewController.swift */; };
96AF96171A5EABC9003926E2 /* StoryTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AF96161A5EABC9003926E2 /* StoryTableViewCell.swift */; };
B773D86F1A7BC101008E8A65 /* LocalStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B773D86E1A7BC101008E8A65 /* LocalStore.swift */; };
B788C5801A8778500011A1A1 /* CustomTransitionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B788C57F1A8778500011A1A1 /* CustomTransitionManager.swift */; };
B78F90381A6EF75800883A5B /* DesignerNewsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B78F90371A6EF75800883A5B /* DesignerNewsService.swift */; };
B78F903E1A6EFAAA00883A5B /* JSONParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = B78F903D1A6EFAAA00883A5B /* JSONParser.swift */; };
B78F90411A6EFBAF00883A5B /* Story.swift in Sources */ = {isa = PBXBuildFile; fileRef = B78F90401A6EFBAF00883A5B /* Story.swift */; };
Expand Down Expand Up @@ -227,6 +228,7 @@
96AF96141A5EAA41003926E2 /* StoriesTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoriesTableViewController.swift; sourceTree = "<group>"; };
96AF96161A5EABC9003926E2 /* StoryTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryTableViewCell.swift; sourceTree = "<group>"; };
B773D86E1A7BC101008E8A65 /* LocalStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalStore.swift; sourceTree = "<group>"; };
B788C57F1A8778500011A1A1 /* CustomTransitionManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomTransitionManager.swift; sourceTree = "<group>"; };
B78F90371A6EF75800883A5B /* DesignerNewsService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DesignerNewsService.swift; sourceTree = "<group>"; };
B78F903D1A6EFAAA00883A5B /* JSONParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONParser.swift; sourceTree = "<group>"; };
B78F90401A6EFBAF00883A5B /* Story.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Story.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -435,6 +437,7 @@
children = (
1A7D789F1A70F8FE0061D6F6 /* DragDropBehavior.swift */,
1A935E3B1A837C640059BCBC /* SoundPlayer+DesignerNewsApp.swift */,
B788C57F1A8778500011A1A1 /* CustomTransitionManager.swift */,
);
name = Behaviours;
sourceTree = "<group>";
Expand Down Expand Up @@ -716,6 +719,7 @@
1A9183091A75EE1900606F35 /* CoreTextView.swift in Sources */,
1A935E3C1A837C640059BCBC /* SoundPlayer+DesignerNewsApp.swift in Sources */,
B7E4D3371A719855001DC9B6 /* CommentTableViewCell.swift in Sources */,
B788C5801A8778500011A1A1 /* CustomTransitionManager.swift in Sources */,
1A2331D21A78E1AF002F8D80 /* StoriesLoader.swift in Sources */,
967CFD061A5C10700044B4E3 /* LoginViewController.swift in Sources */,
9694F2051A5FF13900A6376A /* CommentsTableViewController.swift in Sources */,
Expand Down
14 changes: 12 additions & 2 deletions DesignerNewsApp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="tth-uE-yGl">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6750" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="tth-uE-yGl">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6735"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -565,6 +565,11 @@
<outlet property="webView" destination="weA-Ht-NmR" id="xFo-Mx-cX5"/>
</connections>
</viewController>
<customObject id="OvL-gp-aHq" customClass="CustomTransitionManager" customModule="DesignerNewsApp" customModuleProvider="target">
<connections>
<outlet property="viewController" destination="d4v-hq-Ei2" id="Bkb-dC-h0j"/>
</connections>
</customObject>
<placeholder placeholderIdentifier="IBFirstResponder" id="6aB-Uq-ry8" userLabel="First Responder" sceneMemberID="firstResponder"/>
<exit id="TPO-Ch-8WP" userLabel="Exit" sceneMemberID="exit"/>
</objects>
Expand Down Expand Up @@ -1270,6 +1275,11 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="K7K-nZ-Icz" userLabel="First Responder" sceneMemberID="firstResponder"/>
<exit id="UtX-Fl-8WN" userLabel="Exit" sceneMemberID="exit"/>
<customObject id="fY0-Ow-hyQ" customClass="CustomTransitionManager" customModule="DesignerNewsApp" customModuleProvider="target">
<connections>
<outlet property="viewController" destination="Ud9-EQ-k4v" id="oS0-sB-aRh"/>
</connections>
</customObject>
</objects>
<point key="canvasLocation" x="1638" y="2478"/>
</scene>
Expand Down
3 changes: 0 additions & 3 deletions DesignerNewsApp/CommentsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Spring
class CommentsTableViewController: UITableViewController, StoryTableViewCellDelegate, CommentTableViewCellDelegate, ReplyViewControllerDelegate {

var story: Story!
private let transitionManager = TransitionManager()

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -44,7 +43,6 @@ class CommentsTableViewController: UITableViewController, StoryTableViewCellDele
}

toView.delegate = self
toView.transitioningDelegate = self.transitionManager
}
else if segue.identifier == "WebSegue" {
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.Slide)
Expand All @@ -57,7 +55,6 @@ class CommentsTableViewController: UITableViewController, StoryTableViewCellDele
webViewController.shareTitle = story.title
webViewController.url = NSURL(string: story.url)
}
webViewController.transitioningDelegate = self.transitionManager
}
}

Expand Down
93 changes: 93 additions & 0 deletions DesignerNewsApp/CustomTransitionManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// The MIT License (MIT)
//
// Copyright (c) 2015 Meng To ([email protected])
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import UIKit
import Spring

class CustomTransitionManager: NSObject, UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning {

@IBOutlet weak var viewController: UIViewController! {
didSet {
viewController.transitioningDelegate = self
}
}

private var isPresenting = true
private let duration = 0.3

func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
let container = transitionContext.containerView()
let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
let toView = transitionContext.viewForKey(UITransitionContextToViewKey)!

if isPresenting {
toView.frame = container.bounds
toView.transform = CGAffineTransformMakeTranslation(0, container.frame.size.height)
container.addSubview(fromView)
container.addSubview(toView)
springEaseInOut(duration) {
fromView.transform = CGAffineTransformMakeScale(0.8, 0.8)
fromView.alpha = 0.5
toView.transform = CGAffineTransformIdentity
}
}
else {

// 1. Rotating will change the bounds
// 2. we have to properly reset toView
// to the actual container's bounds, at
// the same time take consideration of
// previous transformation when presenting
let transform = toView.transform
toView.transform = CGAffineTransformIdentity
toView.frame = container.bounds
toView.transform = transform

container.addSubview(toView)
container.addSubview(fromView)

springEaseInOut(duration) {
fromView.transform = CGAffineTransformMakeTranslation(0, fromView.frame.size.height)
toView.transform = CGAffineTransformIdentity
toView.alpha = 1
}
}

delay(duration, {
transitionContext.completeTransition(true)
})
}

func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval {
return duration
}

func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
isPresenting = true
return self
}

func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
isPresenting = false
return self
}
}
5 changes: 1 addition & 4 deletions DesignerNewsApp/StoriesTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import UIKit
import Spring

class StoriesTableViewController: UITableViewController, StoryTableViewCellDelegate, LoginViewControllerDelegate, MenuViewControllerDelegate {

private let transitionManager = TransitionManager()

private var stories = [Story]()
private var firstTime = true
private var storiesLoader = StoriesLoader()
Expand Down Expand Up @@ -226,8 +225,6 @@ class StoriesTableViewController: UITableViewController, StoryTableViewCellDeleg
webViewController.url = url
}

webViewController.transitioningDelegate = self.transitionManager

UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.Slide)
}
else if segue.identifier == "LoginSegue" {
Expand Down