diff --git a/CABook/CABook.xcodeproj/project.pbxproj b/CABook/CABook.xcodeproj/project.pbxproj index 7572066..61936e0 100644 --- a/CABook/CABook.xcodeproj/project.pbxproj +++ b/CABook/CABook.xcodeproj/project.pbxproj @@ -7,6 +7,14 @@ objects = { /* Begin PBXBuildFile section */ + 594B738C1974F2CE004C2735 /* InfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 594B738A1974F2CE004C2735 /* InfoViewController.swift */; }; + 594B738D1974F2CE004C2735 /* InfoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 594B738B1974F2CE004C2735 /* InfoViewController.xib */; }; + 594B73901974F99E004C2735 /* FlatteningViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 594B738E1974F99E004C2735 /* FlatteningViewController.swift */; }; + 594B73911974F99E004C2735 /* FlatteningViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 594B738F1974F99E004C2735 /* FlatteningViewController.xib */; }; + 5986AA5A19725020000F0835 /* GroupOpacityViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5986AA5819725020000F0835 /* GroupOpacityViewController.swift */; }; + 5986AA5B19725020000F0835 /* GroupOpacityViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5986AA5919725020000F0835 /* GroupOpacityViewController.xib */; }; + 5986AA5F1972ACA9000F0835 /* PerspectiveViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5986AA5E1972ACA9000F0835 /* PerspectiveViewController.swift */; }; + 5986AA631972AE7A000F0835 /* PerspectiveViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5986AA621972AE7A000F0835 /* PerspectiveViewController.xib */; }; 59C354D7196E0A89003BEFED /* MasksViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59C354D5196E0A89003BEFED /* MasksViewController.swift */; }; 59C354D8196E0A89003BEFED /* MasksViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 59C354D6196E0A89003BEFED /* MasksViewController.xib */; }; 59C49125196818A8002F75E9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59C49124196818A8002F75E9 /* AppDelegate.swift */; }; @@ -15,6 +23,10 @@ 59C4914019681A59002F75E9 /* ClockViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59C4913E19681A59002F75E9 /* ClockViewController.swift */; }; 59C4914119681A59002F75E9 /* ClockViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 59C4913F19681A59002F75E9 /* ClockViewController.xib */; }; 59C491431968E878002F75E9 /* ListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59C491421968E878002F75E9 /* ListViewController.swift */; }; + 59FED01E19736E5A005B056E /* SublayerTransformViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59FED01C19736E5A005B056E /* SublayerTransformViewController.swift */; }; + 59FED01F19736E5A005B056E /* SublayerTransformViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 59FED01D19736E5A005B056E /* SublayerTransformViewController.xib */; }; + 59FED022197371F7005B056E /* BackviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59FED020197371F7005B056E /* BackviewViewController.swift */; }; + 59FED023197371F7005B056E /* BackviewViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 59FED021197371F7005B056E /* BackviewViewController.xib */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -28,6 +40,14 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 594B738A1974F2CE004C2735 /* InfoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InfoViewController.swift; sourceTree = ""; }; + 594B738B1974F2CE004C2735 /* InfoViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = InfoViewController.xib; sourceTree = ""; }; + 594B738E1974F99E004C2735 /* FlatteningViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlatteningViewController.swift; sourceTree = ""; }; + 594B738F1974F99E004C2735 /* FlatteningViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FlatteningViewController.xib; sourceTree = ""; }; + 5986AA5819725020000F0835 /* GroupOpacityViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupOpacityViewController.swift; sourceTree = ""; }; + 5986AA5919725020000F0835 /* GroupOpacityViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GroupOpacityViewController.xib; sourceTree = ""; }; + 5986AA5E1972ACA9000F0835 /* PerspectiveViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerspectiveViewController.swift; sourceTree = ""; }; + 5986AA621972AE7A000F0835 /* PerspectiveViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PerspectiveViewController.xib; sourceTree = ""; }; 59C354D5196E0A89003BEFED /* MasksViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MasksViewController.swift; sourceTree = ""; }; 59C354D6196E0A89003BEFED /* MasksViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MasksViewController.xib; sourceTree = ""; }; 59C4911F196818A8002F75E9 /* CABook.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CABook.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -40,6 +60,10 @@ 59C4913E19681A59002F75E9 /* ClockViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClockViewController.swift; sourceTree = ""; }; 59C4913F19681A59002F75E9 /* ClockViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ClockViewController.xib; sourceTree = ""; }; 59C491421968E878002F75E9 /* ListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListViewController.swift; sourceTree = ""; }; + 59FED01C19736E5A005B056E /* SublayerTransformViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SublayerTransformViewController.swift; sourceTree = ""; }; + 59FED01D19736E5A005B056E /* SublayerTransformViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SublayerTransformViewController.xib; sourceTree = ""; }; + 59FED020197371F7005B056E /* BackviewViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackviewViewController.swift; sourceTree = ""; }; + 59FED021197371F7005B056E /* BackviewViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BackviewViewController.xib; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -60,11 +84,28 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 5986AA5D1972AC95000F0835 /* Chapter 5 */ = { + isa = PBXGroup; + children = ( + 5986AA5E1972ACA9000F0835 /* PerspectiveViewController.swift */, + 5986AA621972AE7A000F0835 /* PerspectiveViewController.xib */, + 59FED01C19736E5A005B056E /* SublayerTransformViewController.swift */, + 59FED01D19736E5A005B056E /* SublayerTransformViewController.xib */, + 59FED020197371F7005B056E /* BackviewViewController.swift */, + 59FED021197371F7005B056E /* BackviewViewController.xib */, + 594B738E1974F99E004C2735 /* FlatteningViewController.swift */, + 594B738F1974F99E004C2735 /* FlatteningViewController.xib */, + ); + name = "Chapter 5"; + sourceTree = ""; + }; 59C354D4196E0A77003BEFED /* Chapter 4 */ = { isa = PBXGroup; children = ( 59C354D5196E0A89003BEFED /* MasksViewController.swift */, 59C354D6196E0A89003BEFED /* MasksViewController.xib */, + 5986AA5819725020000F0835 /* GroupOpacityViewController.swift */, + 5986AA5919725020000F0835 /* GroupOpacityViewController.xib */, ); name = "Chapter 4"; sourceTree = ""; @@ -94,6 +135,8 @@ 59C49124196818A8002F75E9 /* AppDelegate.swift */, 59C49126196818A8002F75E9 /* Images.xcassets */, 59C49122196818A8002F75E9 /* Supporting Files */, + 594B738A1974F2CE004C2735 /* InfoViewController.swift */, + 594B738B1974F2CE004C2735 /* InfoViewController.xib */, ); path = CABook; sourceTree = ""; @@ -126,6 +169,7 @@ 59C4913C196818DE002F75E9 /* Chapters */ = { isa = PBXGroup; children = ( + 5986AA5D1972AC95000F0835 /* Chapter 5 */, 59C354D4196E0A77003BEFED /* Chapter 4 */, 59C4913D196818E8002F75E9 /* Chapter 3 */, 59C491421968E878002F75E9 /* ListViewController.swift */, @@ -221,9 +265,15 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5986AA5B19725020000F0835 /* GroupOpacityViewController.xib in Resources */, 59C49127196818A8002F75E9 /* Images.xcassets in Resources */, + 594B738D1974F2CE004C2735 /* InfoViewController.xib in Resources */, + 59FED01F19736E5A005B056E /* SublayerTransformViewController.xib in Resources */, + 594B73911974F99E004C2735 /* FlatteningViewController.xib in Resources */, 59C354D8196E0A89003BEFED /* MasksViewController.xib in Resources */, 59C4914119681A59002F75E9 /* ClockViewController.xib in Resources */, + 5986AA631972AE7A000F0835 /* PerspectiveViewController.xib in Resources */, + 59FED023197371F7005B056E /* BackviewViewController.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -243,7 +293,13 @@ files = ( 59C49125196818A8002F75E9 /* AppDelegate.swift in Sources */, 59C4914019681A59002F75E9 /* ClockViewController.swift in Sources */, + 594B73901974F99E004C2735 /* FlatteningViewController.swift in Sources */, + 59FED022197371F7005B056E /* BackviewViewController.swift in Sources */, 59C354D7196E0A89003BEFED /* MasksViewController.swift in Sources */, + 594B738C1974F2CE004C2735 /* InfoViewController.swift in Sources */, + 5986AA5F1972ACA9000F0835 /* PerspectiveViewController.swift in Sources */, + 5986AA5A19725020000F0835 /* GroupOpacityViewController.swift in Sources */, + 59FED01E19736E5A005B056E /* SublayerTransformViewController.swift in Sources */, 59C491431968E878002F75E9 /* ListViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/CABook/CABook.xcodeproj/project.xcworkspace/xcshareddata/CABook.xccheckout b/CABook/CABook.xcodeproj/project.xcworkspace/xcshareddata/CABook.xccheckout new file mode 100644 index 0000000..8a2728a --- /dev/null +++ b/CABook/CABook.xcodeproj/project.xcworkspace/xcshareddata/CABook.xccheckout @@ -0,0 +1,41 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + 76B40F24-0A8A-4B8B-B19F-8776DF1B98C8 + IDESourceControlProjectName + CABook + IDESourceControlProjectOriginsDictionary + + 3479137E-F792-485E-838F-B9CAB3A5010D + ssh://github.com/raheelahmad/CABook.git + + IDESourceControlProjectPath + CABook/CABook.xcodeproj/project.xcworkspace + IDESourceControlProjectRelativeInstallPathDictionary + + 3479137E-F792-485E-838F-B9CAB3A5010D + ../../.. + + IDESourceControlProjectURL + ssh://github.com/raheelahmad/CABook.git + IDESourceControlProjectVersion + 110 + IDESourceControlProjectWCCIdentifier + 3479137E-F792-485E-838F-B9CAB3A5010D + IDESourceControlProjectWCConfigurations + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + 3479137E-F792-485E-838F-B9CAB3A5010D + IDESourceControlWCCName + CABook + + + + diff --git a/CABook/CABook.xcodeproj/project.xcworkspace/xcuserdata/raheel.xcuserdatad/UserInterfaceState.xcuserstate b/CABook/CABook.xcodeproj/project.xcworkspace/xcuserdata/raheel.xcuserdatad/UserInterfaceState.xcuserstate index 0116b22..149abf2 100644 Binary files a/CABook/CABook.xcodeproj/project.xcworkspace/xcuserdata/raheel.xcuserdatad/UserInterfaceState.xcuserstate and b/CABook/CABook.xcodeproj/project.xcworkspace/xcuserdata/raheel.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/CABook/CABook/BackviewViewController.swift b/CABook/CABook/BackviewViewController.swift new file mode 100644 index 0000000..af0426f --- /dev/null +++ b/CABook/CABook/BackviewViewController.swift @@ -0,0 +1,59 @@ +// +// BackviewViewController.swift +// CABook +// +// Created by Raheel Ahmad on 7/13/14. +// Copyright (c) 2014 Sakun Labs. All rights reserved. +// + +import UIKit +import QuartzCore + +@objc(BackviewViewController) class BackviewViewController: UIViewController { + + @IBOutlet strong var tajView: UIImageView! + + var timer: NSTimer? + var tickCount = 0 + + @IBAction func switchDoubleSidedness(sender: UISwitch) { + tajView.layer.doubleSided = sender.on + } + + @IBAction func showInfo(sender: AnyObject) { + let info = "The doubleSided property controls whether the layer's back view (when rotated by 180° on its x or y axis) is a mirror of its front contents or not." + let infoVC = InfoViewController(info: info) + presentViewController(infoVC, animated: true, completion: nil) + } + + override func viewWillAppear(animated: Bool) { + super.viewWillAppear(animated) + tajView.layer.borderColor = UIColor.darkGrayColor().CGColor + tajView.layer.borderWidth = 1.0 + animate() + } + + override func viewWillDisappear(animated: Bool) { + super.viewWillDisappear(animated) + timer!.invalidate() + } + + func animate() { + timer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: "tick", userInfo: nil, repeats: true) + tickCount = 0 + tick() + } + + func tick() { + if tickCount > 360 { + tickCount = 0 + } + let angle = Double(tickCount) * M_PI / 180 + var transform = CATransform3DIdentity + transform.m34 = -1/500.0 + transform = CATransform3DRotate(transform, CGFloat(angle), 0, 1, 0) + tajView.layer.transform = transform + + tickCount++ + } +} diff --git a/CABook/CABook/BackviewViewController.xib b/CABook/CABook/BackviewViewController.xib new file mode 100644 index 0000000..e45236b --- /dev/null +++ b/CABook/CABook/BackviewViewController.xib @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CABook/CABook/ClockViewController.xib b/CABook/CABook/ClockViewController.xib index cce27e1..b5acfad 100644 --- a/CABook/CABook/ClockViewController.xib +++ b/CABook/CABook/ClockViewController.xib @@ -1,7 +1,7 @@ - + - + @@ -46,9 +46,7 @@ - - diff --git a/CABook/CABook/FlatteningViewController.swift b/CABook/CABook/FlatteningViewController.swift new file mode 100644 index 0000000..0cc2f1a --- /dev/null +++ b/CABook/CABook/FlatteningViewController.swift @@ -0,0 +1,48 @@ +// +// FlatteningViewController.swift +// CABook +// +// Created by Raheel Ahmad on 7/14/14. +// Copyright (c) 2014 Sakun Labs. All rights reserved. +// + +import UIKit +import QuartzCore + +@objc(FlatteningViewController) class FlatteningViewController: UIViewController { + + enum Axis: Int { + case Z = 0 + case X + } + + @IBOutlet var outerView: UIView + @IBOutlet var innerView: UIView + @IBOutlet var `switch`: UISegmentedControl + + override func viewDidLoad() { + super.viewDidLoad() + + applyRotation(nil) + } + + @IBAction func showInfo(sender: AnyObject) { + let info = "Applying an opposite transform to nested layers \"corrects\" them for rotations in X or Y axis. For 3D rotations (in Z axis) however, the correction doesn't apply. As the layer's sublayers are flattened, so the sublayer rotation doesn't have the cancelling effect." + let infoVC = InfoViewController(info: info) + presentViewController(infoVC, animated: true, completion: nil) + } + + @IBAction func applyRotation(sender: AnyObject?) { + switch Axis.fromRaw(`switch`.selectedSegmentIndex) as Axis { + case Axis.Z: + outerView.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI_4), 0, 0, 1) + innerView.layer.transform = CATransform3DMakeRotation(CGFloat(-M_PI_4), 0, 0, 1) + case .X: + outerView.layer.transform = CATransform3DMakeRotation(CGFloat(M_PI_4), 1, 0, 1) + innerView.layer.transform = CATransform3DMakeRotation(CGFloat(-M_PI_4), 1, 0, 1) + default: + break + } + + } +} diff --git a/CABook/CABook/FlatteningViewController.xib b/CABook/CABook/FlatteningViewController.xib new file mode 100644 index 0000000..e8f7310 --- /dev/null +++ b/CABook/CABook/FlatteningViewController.xib @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CABook/CABook/GroupOpacityViewController.swift b/CABook/CABook/GroupOpacityViewController.swift new file mode 100644 index 0000000..5f991ab --- /dev/null +++ b/CABook/CABook/GroupOpacityViewController.swift @@ -0,0 +1,47 @@ +// +// GroupOpacityViewController.swift +// CABook +// +// Created by Raheel Ahmad on 7/12/14. +// Copyright (c) 2014 Sakun Labs. All rights reserved. +// + +import UIKit + +@objc(GroupOpacityViewController) class GroupOpacityViewController: UIViewController { + + @IBOutlet var topButton: UIButton + @IBOutlet var bottomButton: UIButton + + convenience init() { + self.init(nibName: "GroupOpacityViewController", bundle: nil) + } + + init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { + super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) + } + + func setupButtons() { + for btn in [ topButton, bottomButton ] { + let w = btn.bounds.width + let h = btn.bounds.height + let someLabel = UILabel(frame: CGRectMake(0, h/2 - 10, w, 20)) + someLabel.text = "Button Label" + someLabel.backgroundColor = UIColor.whiteColor() + someLabel.textAlignment = .Center + btn.addSubview(someLabel) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + setupButtons() + topButton.layer.opacity = 0.5 + + bottomButton.layer.shouldRasterize = true + bottomButton.layer.rasterizationScale = UIScreen.mainScreen().scale + bottomButton.layer.opacity = 0.5 + } + +} diff --git a/CABook/CABook/GroupOpacityViewController.xib b/CABook/CABook/GroupOpacityViewController.xib new file mode 100644 index 0000000..5635c5e --- /dev/null +++ b/CABook/CABook/GroupOpacityViewController.xib @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CABook/CABook/Images.xcassets/pattern.imageset/Contents.json b/CABook/CABook/Images.xcassets/pattern.imageset/Contents.json new file mode 100644 index 0000000..f6e31ee --- /dev/null +++ b/CABook/CABook/Images.xcassets/pattern.imageset/Contents.json @@ -0,0 +1,20 @@ +{ + "images" : [ + { + "idiom" : "universal" + }, + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "pattern.png" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/CABook/CABook/Images.xcassets/pattern.imageset/pattern.png b/CABook/CABook/Images.xcassets/pattern.imageset/pattern.png new file mode 100644 index 0000000..534cad4 Binary files /dev/null and b/CABook/CABook/Images.xcassets/pattern.imageset/pattern.png differ diff --git a/CABook/CABook/InfoViewController.swift b/CABook/CABook/InfoViewController.swift new file mode 100644 index 0000000..be30393 --- /dev/null +++ b/CABook/CABook/InfoViewController.swift @@ -0,0 +1,37 @@ +// +// InfoViewController.swift +// CABook +// +// Created by Raheel Ahmad on 7/14/14. +// Copyright (c) 2014 Sakun Labs. All rights reserved. +// + +import UIKit + +class InfoViewController: UIViewController { + var info: String? + + @IBOutlet var textView: UITextView + convenience init(info: String) { + self.init() + self.info = info + } + + override func viewWillAppear(animated: Bool) { + super.viewWillAppear(animated) + + textView.text = info + } + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + } +} + +extension InfoViewController { + @IBAction func done(sender: AnyObject) { + dismissViewControllerAnimated(true, completion: nil) + } +} diff --git a/CABook/CABook/InfoViewController.xib b/CABook/CABook/InfoViewController.xib new file mode 100644 index 0000000..ea644a3 --- /dev/null +++ b/CABook/CABook/InfoViewController.xib @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + 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. + + + + + + + + + + + + + + + + + diff --git a/CABook/CABook/ListViewController.swift b/CABook/CABook/ListViewController.swift index 84d9fb0..fbc07e3 100644 --- a/CABook/CABook/ListViewController.swift +++ b/CABook/CABook/ListViewController.swift @@ -12,7 +12,8 @@ struct List { static let chapters = [ [chapterKey: "Chapter 3", exercisesKey: [ "Clock" ]], - [chapterKey: "Chapter 4", exercisesKey: [ "Masks" ]], + [chapterKey: "Chapter 4", exercisesKey: [ "Masks", "GroupOpacity" ]], + [chapterKey: "Chapter 5", exercisesKey: [ "Perspective", "SublayerTransform", "Backview", "Flattening" ]], ] static let nameKey = "name" static let chapterKey = "chapterName" diff --git a/CABook/CABook/PerspectiveViewController.swift b/CABook/CABook/PerspectiveViewController.swift new file mode 100644 index 0000000..5d45bf6 --- /dev/null +++ b/CABook/CABook/PerspectiveViewController.swift @@ -0,0 +1,64 @@ +// +// PerspectiveViewController.swift +// CABook +// +// Created by Raheel Ahmad on 7/13/14. +// Copyright (c) 2014 Sakun Labs. All rights reserved. +// + +import UIKit +import QuartzCore + +@objc(PerspectiveViewController) class PerspectiveViewController: UIViewController { + + @IBOutlet strong var tajWidthConstraint: NSLayoutConstraint! + @IBOutlet strong var tajHeightConstraint: NSLayoutConstraint! + @IBOutlet var tajView: UIImageView + @IBOutlet var slider: UISlider + var hConstraints: [NSLayoutConstraint] = [] + var wConstraints: [NSLayoutConstraint] = [] + override func viewDidLoad() { + super.viewDidLoad() + + addInfoButton() + } + + @IBAction func sliderValueChanged(sender: AnyObject) { + view.removeConstraint(tajWidthConstraint) + view.removeConstraint(tajHeightConstraint) + + let fraction = slider.value + let value = 500.0 + fraction * (1000 - 500) + + var transform = CATransform3DIdentity + transform.m34 = -1.0/value + transform = CATransform3DRotate(transform, CGFloat(M_PI_4), 0, 1, 0) + + tajView.layer.transform = transform + } + + func addInfoButton() { + let view = self.view + + let w = view.bounds.size.width + let h = view.bounds.size.height + let button = UIButton.buttonWithType(.InfoDark) as UIButton + button.setTranslatesAutoresizingMaskIntoConstraints(false) + button.addTarget(self, action: "showInfo", forControlEvents: .TouchUpInside) + view.addSubview(button) + + let vd = [ "view": view, "button": button ] + let md = [ "width": 24, "spacing": 10 ] + view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[button(width)]-spacing-|", options: nil, metrics: md, views: vd)) + view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[button(width)]-spacing-|", options: nil, metrics: md, views: vd)) + } + + func showInfo() { + let vc = UIViewController() + let w = view.bounds.size.width + let h = view.bounds.size.height + vc.view.frame = CGRect(x: 0, y: h - 140, width: w, height: 140) + vc.view.backgroundColor = UIColor.redColor() + self.presentViewController(vc, animated: true, completion: nil) + } +} diff --git a/CABook/CABook/PerspectiveViewController.xib b/CABook/CABook/PerspectiveViewController.xib new file mode 100644 index 0000000..dadc929 --- /dev/null +++ b/CABook/CABook/PerspectiveViewController.xib @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CABook/CABook/SublayerTransformViewController.swift b/CABook/CABook/SublayerTransformViewController.swift new file mode 100644 index 0000000..9b0486f --- /dev/null +++ b/CABook/CABook/SublayerTransformViewController.swift @@ -0,0 +1,31 @@ +// +// SublayerTransformViewController.swift +// CABook +// +// Created by Raheel Ahmad on 7/13/14. +// Copyright (c) 2014 Sakun Labs. All rights reserved. +// + +import UIKit +import QuartzCore + +@objc(SublayerTransformViewController) class SublayerTransformViewController: UIViewController { + + @IBOutlet strong var taj1: UIImageView! + @IBOutlet strong var taj2: UIImageView! + override func viewDidLoad() { + super.viewDidLoad() + + applyTransform() + } + + func applyTransform() { + var transform = CATransform3DIdentity + transform.m34 = -1.0/500.0 + view.layer.sublayerTransform = transform + + taj1.layer.transform = CATransform3DRotate(transform, -CGFloat(M_PI_4), 0, 1, 0) + taj2.layer.transform = CATransform3DRotate(transform, CGFloat(M_PI_4), 0, 1, 0) + } + +} diff --git a/CABook/CABook/SublayerTransformViewController.xib b/CABook/CABook/SublayerTransformViewController.xib new file mode 100644 index 0000000..11e491f --- /dev/null +++ b/CABook/CABook/SublayerTransformViewController.xib @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +