Skip to content

Commit

Permalink
Added an instructions view and a generic paged game view
Browse files Browse the repository at this point in the history
  • Loading branch information
ignat980 committed Dec 18, 2015
1 parent 3fec504 commit eb28b06
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 4 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/Users/ignat/Documents/Programming/ios-ios-baby/Swiftastic/Make School/Improv Guide/DerivedData/Improv Guide/Build/Intermediates/Improv Guide.build/Debug-iphonesimulator/Improv Guide.build/Objects-normal/x86_64/MenuViewController.o
/Users/ignat/Documents/Programming/ios-ios-baby/Swiftastic/Make School/Improv Guide/DerivedData/Improv Guide/Build/Intermediates/Improv Guide.build/Debug-iphonesimulator/Improv Guide.build/Objects-normal/x86_64/PagedGameViewController.o
/Users/ignat/Documents/Programming/ios-ios-baby/Swiftastic/Make School/Improv Guide/DerivedData/Improv Guide/Build/Intermediates/Improv Guide.build/Debug-iphonesimulator/Improv Guide.build/Objects-normal/x86_64/AppDelegate.o
/Users/ignat/Documents/Programming/ios-ios-baby/Swiftastic/Make School/Improv Guide/DerivedData/Improv Guide/Build/Intermediates/Improv Guide.build/Debug-iphonesimulator/Improv Guide.build/Objects-normal/x86_64/GamePageViewController.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions Improv Guide.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CD7B4C901C1AF01500CE36DC /* Data.plist in Resources */ = {isa = PBXBuildFile; fileRef = CD7B4C8F1C1AF01500CE36DC /* Data.plist */; };
CDE249251C1CFD8100F7B098 /* InstructionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE249241C1CFD8100F7B098 /* InstructionsViewController.swift */; };
CDE249271C1F4F2900F7B098 /* PagedGameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE249261C1F4F2900F7B098 /* PagedGameViewController.swift */; };
CDE249291C1F62F500F7B098 /* GamePageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDE249281C1F62F500F7B098 /* GamePageViewController.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -53,6 +54,7 @@
CD7B4C8F1C1AF01500CE36DC /* Data.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Data.plist; sourceTree = "<group>"; };
CDE249241C1CFD8100F7B098 /* InstructionsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InstructionsViewController.swift; sourceTree = "<group>"; };
CDE249261C1F4F2900F7B098 /* PagedGameViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagedGameViewController.swift; sourceTree = "<group>"; };
CDE249281C1F62F500F7B098 /* GamePageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GamePageViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -107,6 +109,7 @@
CD6C44731C1AE6AF00B2141C /* MenuViewController.swift */,
CDE249241C1CFD8100F7B098 /* InstructionsViewController.swift */,
CD6C44751C1AE6B000B2141C /* Main.storyboard */,
CDE249281C1F62F500F7B098 /* GamePageViewController.swift */,
CDE249261C1F4F2900F7B098 /* PagedGameViewController.swift */,
CD6C44781C1AE6B000B2141C /* Assets.xcassets */,
CD6C447A1C1AE6B000B2141C /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -270,6 +273,7 @@
CD6C44741C1AE6AF00B2141C /* MenuViewController.swift in Sources */,
CDE249271C1F4F2900F7B098 /* PagedGameViewController.swift in Sources */,
CD6C44721C1AE6AF00B2141C /* AppDelegate.swift in Sources */,
CDE249291C1F62F500F7B098 /* GamePageViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
5 changes: 3 additions & 2 deletions Improv Guide/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand Down
72 changes: 71 additions & 1 deletion Improv Guide/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
<subviews>
<navigationBar contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="WoJ-LF-K87">
<rect key="frame" x="0.0" y="20" width="600" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="60" id="2KR-J0-OEh"/>
</constraints>
<items>
<navigationItem title="Title" id="8Ob-j5-HKq">
<barButtonItem key="leftBarButtonItem" systemItem="stop" id="NO2-NK-17Y">
Expand All @@ -67,6 +70,11 @@
</barButtonItem>
</navigationItem>
</items>
<variation key="default">
<mask key="constraints">
<exclude reference="2KR-J0-OEh"/>
</mask>
</variation>
</navigationBar>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="aUX-YI-BPO" userLabel="Separator">
<rect key="frame" x="0.0" y="64" width="580" height="3"/>
Expand All @@ -78,7 +86,7 @@
<constraint firstAttribute="height" constant="3" id="4ms-tm-Y9L"/>
</constraints>
</view>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="aFa-Cb-QDh" userLabel="Description">
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="aFa-Cb-QDh" userLabel="Description">
<rect key="frame" x="16" y="67" width="548" height="533"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
Expand All @@ -93,6 +101,17 @@
</mask>
</variation>
</textView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="pz0-24-4EK">
<rect key="frame" x="163" y="448" width="255" height="121"/>
<constraints>
<constraint firstAttribute="height" constant="121" id="0Jg-3q-kOs"/>
<constraint firstAttribute="width" constant="255" id="LXV-5d-0d7"/>
</constraints>
<state key="normal" title="Button"/>
<connections>
<segue destination="Iu1-2O-dZ5" kind="show" identifier="startGame" id="J4a-4s-ElL"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
Expand All @@ -103,19 +122,23 @@
<constraint firstItem="aFa-Cb-QDh" firstAttribute="leading" secondItem="Tox-Os-w9T" secondAttribute="leadingMargin" constant="-4" id="FM4-YO-w3n"/>
<constraint firstItem="aUX-YI-BPO" firstAttribute="centerX" secondItem="aFa-Cb-QDh" secondAttribute="centerX" id="FUr-iM-RYz"/>
<constraint firstItem="aUX-YI-BPO" firstAttribute="top" secondItem="WoJ-LF-K87" secondAttribute="bottom" id="HYO-cV-C5a"/>
<constraint firstItem="pz0-24-4EK" firstAttribute="top" secondItem="aFa-Cb-QDh" secondAttribute="bottom" constant="-152" id="IxL-hD-IE8"/>
<constraint firstItem="aUX-YI-BPO" firstAttribute="trailing" secondItem="WoJ-LF-K87" secondAttribute="trailing" id="Izm-ml-Cyc"/>
<constraint firstItem="aFa-Cb-QDh" firstAttribute="top" secondItem="aUX-YI-BPO" secondAttribute="bottom" id="Mwd-tt-4q0"/>
<constraint firstItem="aUX-YI-BPO" firstAttribute="leading" secondItem="Tox-Os-w9T" secondAttribute="leading" id="O7p-zy-E4t"/>
<constraint firstItem="aUX-YI-BPO" firstAttribute="trailing" secondItem="Tox-Os-w9T" secondAttribute="trailingMargin" id="Odf-0S-kgf"/>
<constraint firstItem="aFa-Cb-QDh" firstAttribute="top" secondItem="aUX-YI-BPO" secondAttribute="bottom" id="SPC-um-GNx"/>
<constraint firstItem="0Gx-Sa-4OU" firstAttribute="top" secondItem="pz0-24-4EK" secondAttribute="bottom" constant="31" id="YnV-xh-jLR"/>
<constraint firstItem="0Gx-Sa-4OU" firstAttribute="top" secondItem="aUX-YI-BPO" secondAttribute="bottom" constant="548" id="nzk-vu-52B"/>
<constraint firstItem="pz0-24-4EK" firstAttribute="centerX" secondItem="aUX-YI-BPO" secondAttribute="centerX" id="tpM-vc-vv4"/>
<constraint firstItem="aFa-Cb-QDh" firstAttribute="top" secondItem="aUX-YI-BPO" secondAttribute="bottom" id="ydU-k7-ym3"/>
</constraints>
<variation key="default">
<mask key="constraints">
<exclude reference="Izm-ml-Cyc"/>
<exclude reference="Mwd-tt-4q0"/>
<exclude reference="ydU-k7-ym3"/>
<exclude reference="YnV-xh-jLR"/>
<exclude reference="nzk-vu-52B"/>
</mask>
</variation>
Expand All @@ -130,5 +153,52 @@
</objects>
<point key="canvasLocation" x="1011" y="377"/>
</scene>
<!--Paged Game View Controller-->
<scene sceneID="pZ9-4Q-8MJ">
<objects>
<pageViewController storyboardIdentifier="pagedGameController" autoresizesArchivedViewToFullSize="NO" useStoryboardIdentifierAsRestorationIdentifier="YES" transitionStyle="pageCurl" navigationOrientation="horizontal" spineLocation="none" id="Iu1-2O-dZ5" customClass="PagedGameViewController" customModule="Improv_Guide" customModuleProvider="target" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="yv3-Vf-9C8" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1737" y="377"/>
</scene>
<!--Game Page View Controller-->
<scene sceneID="Ra0-Cg-Ehb">
<objects>
<viewController storyboardIdentifier="gamePageController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="5Wt-2d-oIl" customClass="GamePageViewController" customModule="Improv_Guide" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="ZJn-Cc-hyX"/>
<viewControllerLayoutGuide type="bottom" id="sCF-iO-zXB"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="41i-gC-fXw">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="jZZ-ta-H6L">
<rect key="frame" x="0.0" y="207" width="600" height="187"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="187" id="gcP-Lc-3ZQ"/>
</constraints>
<mutableString key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</mutableString>
<fontDescription key="fontDescription" type="system" pointSize="36"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="jZZ-ta-H6L" firstAttribute="centerX" secondItem="41i-gC-fXw" secondAttribute="centerX" id="Vey-wq-fqd"/>
<constraint firstItem="jZZ-ta-H6L" firstAttribute="leading" secondItem="41i-gC-fXw" secondAttribute="leading" id="cqo-4D-3Oz"/>
<constraint firstItem="jZZ-ta-H6L" firstAttribute="centerY" secondItem="41i-gC-fXw" secondAttribute="centerY" id="g50-YB-JJY"/>
<constraint firstAttribute="trailing" secondItem="jZZ-ta-H6L" secondAttribute="trailing" id="zEi-rt-4PA"/>
</constraints>
</view>
<connections>
<outlet property="instructions" destination="jZZ-ta-H6L" id="YpX-Z0-EiS"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qug-Tg-mhl" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1737" y="1092"/>
</scene>
</scenes>
</document>
38 changes: 38 additions & 0 deletions Improv Guide/GamePageViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// GamePageViewController.swift
// Improv Guide
//
// Created by Ignat Remizov on 12/14/15.
// Copyright © 2015 Ignat Remizov. All rights reserved.
//

import UIKit

class GamePageViewController: UIViewController {

@IBOutlet var instructions: UITextView!
var step:Int = 0

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.
}


/*
// 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.
}
*/

}
8 changes: 8 additions & 0 deletions Improv Guide/InstructionsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class InstructionsViewController: UIViewController {
@IBAction func closeButtonPressed(sender:AnyObject) {
self.dismissViewControllerAnimated(true, completion:nil)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "startGame" {
if let game = segue.destinationViewController as? PagedGameViewController {
game.gameData = gameData
}
}
}
/*
// MARK: - Navigation
Expand Down
80 changes: 80 additions & 0 deletions Improv Guide/PagedGameViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// PagedGameViewController.swift
// Improv Guide
//
// Created by Ignat Remizov on 12/14/15.
// Copyright © 2015 Ignat Remizov. All rights reserved.
//

import UIKit

class PagedGameViewController: UIPageViewController {

var gameData: NSDictionary?

override func viewDidLoad() {
super.viewDidLoad()
self.dataSource = self
if let game = self.storyboard?.instantiateViewControllerWithIdentifier("gamePageController") as? GamePageViewController {
self.setViewControllers([game], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
game.instructions.text = ""
game.instructions.text = (gameData?.valueForKeyPathWithIndexes("Parts[0]") as? String ?? "")
game.step = 0

}
}


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


/*
// 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.
}
*/

}

extension PagedGameViewController:UIPageViewControllerDataSource {

func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
let gameVC = viewController as! GamePageViewController
if gameVC.step == 0 {
return nil
}
let game = self.storyboard?.instantiateViewControllerWithIdentifier("gamePageController") as! GamePageViewController
let _ = game.view
game.step = gameVC.step - 1
game.instructions.text = gameData?.valueForKeyPathWithIndexes("Parts[\(gameVC.step - 1)]") as? String ?? ""
return game
}

func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
let gameVC = viewController as! GamePageViewController
if gameVC.step + 1 >= self.gameData?.valueForKeyPath("Parts.@count") as? Int ?? 0 {
return nil
}
let game = self.storyboard?.instantiateViewControllerWithIdentifier("gamePageController") as! GamePageViewController
let _ = game.view
game.step = gameVC.step + 1
game.instructions.text = gameData?.valueForKeyPathWithIndexes("Parts[\(game.step)]") as? String ?? ""

return game
}

func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
return self.gameData?.valueForKeyPath("Parts.@count") as? Int ?? 0
}

func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0
}
}

0 comments on commit eb28b06

Please sign in to comment.