refactor ShowStepViewController

This commit is contained in:
nixzhu
2015-08-20 14:56:32 +08:00
parent ecadd85089
commit f79dc7e834
5 changed files with 34 additions and 72 deletions
+7 -18
View File
@@ -59,24 +59,6 @@
</objects>
<point key="canvasLocation" x="348" y="330"/>
</scene>
<!--Show Step View Controller-->
<scene sceneID="Se2-zL-QXr">
<objects>
<viewController storyboardIdentifier="ShowStepViewController" id="7gO-WP-Qin" customClass="ShowStepViewController" customModule="Yep" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="BQ6-y1-4TP"/>
<viewControllerLayoutGuide type="bottom" id="ue7-Md-6gH"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="wdD-Wr-EhK">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="CaN-5t-F2i" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="348" y="1046"/>
</scene>
<!--Show Step Genius View Controller-->
<scene sceneID="PLw-aM-8MV">
<objects>
@@ -278,6 +260,13 @@
</constraints>
</view>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina47"/>
<connections>
<outlet property="book" destination="L7f-XP-WgV" id="sYX-Lr-8fR"/>
<outlet property="camera" destination="Sij-Kk-TC5" id="nok-ua-LNu"/>
<outlet property="controller" destination="6nM-wS-8be" id="xhA-Os-Qio"/>
<outlet property="keyboard" destination="Cja-9u-yQO" id="dST-wH-vPB"/>
<outlet property="pen" destination="ofE-QC-oZA" id="s36-xU-FzA"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="eRf-2b-6t8" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
@@ -8,7 +8,7 @@
import UIKit
class ShowStepGeniusViewController: UIViewController {
class ShowStepGeniusViewController: ShowStepViewController {
@IBOutlet weak var rightPurpleDot: UIImageView!
@IBOutlet weak var leftGreenDot: UIImageView!
@@ -46,21 +46,5 @@ class ShowStepGeniusViewController: UIViewController {
let dotsLinkPath = UIBezierPath(arcCenter: dotsLink.center, radius: 5, startAngle: 0, endAngle: 2, clockwise: false)
repeatAnimate(dotsLink, alongWithPath: dotsLinkPath, duration: 7, autoreverses: true)
}
func repeatAnimate(view: UIView, alongWithPath path: UIBezierPath, duration: CFTimeInterval, autoreverses: Bool = false) {
let animation = CAKeyframeAnimation(keyPath: "position")
animation.calculationMode = kCAAnimationPaced
animation.fillMode = kCAFillModeForwards
animation.duration = duration
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.repeatCount = Float.infinity
animation.autoreverses = autoreverses
animation.path = path.CGPath
view.layer.addAnimation(animation, forKey: "Animation")
}
}
@@ -8,28 +8,22 @@
import UIKit
class ShowStepMatchViewController: UIViewController {
class ShowStepMatchViewController: ShowStepViewController {
@IBOutlet weak var camera: UIImageView!
@IBOutlet weak var pen: UIImageView!
@IBOutlet weak var book: UIImageView!
@IBOutlet weak var controller: UIImageView!
@IBOutlet weak var keyboard: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
@@ -10,9 +10,19 @@ import UIKit
class ShowStepViewController: UIViewController {
var showName: String?
func repeatAnimate(view: UIView, alongWithPath path: UIBezierPath, duration: CFTimeInterval, autoreverses: Bool = false) {
override func viewDidLoad() {
super.viewDidLoad()
let animation = CAKeyframeAnimation(keyPath: "position")
animation.calculationMode = kCAAnimationPaced
animation.fillMode = kCAFillModeForwards
animation.duration = duration
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.repeatCount = Float.infinity
animation.autoreverses = autoreverses
animation.path = path.CGPath
view.layer.addAnimation(animation, forKey: "Animation")
}
}
@@ -28,7 +28,7 @@ class ShowViewController: UIViewController {
let stepA = stepGenius()
let stepB = stepMatch()
let stepC = step("Yep Intro")
let stepC = stepMatch()
steps = [stepA, stepB, stepC]
@@ -79,21 +79,6 @@ class ShowViewController: UIViewController {
return step
}
private func step(name: String) -> ShowStepViewController {
let step = storyboard!.instantiateViewControllerWithIdentifier("ShowStepViewController") as! ShowStepViewController
step.showName = name
step.view.setTranslatesAutoresizingMaskIntoConstraints(false)
scrollView.addSubview(step.view)
addChildViewController(step)
step.didMoveToParentViewController(self)
return step
}
// MARK: Actions
@IBAction func finish(sender: UIButton) {