Skip to content

Commit

Permalink
Updated sample project to Swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ Hanson committed Jul 14, 2016
1 parent 09153f8 commit c4dab16
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 119 deletions.
5 changes: 4 additions & 1 deletion TAAESample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "A Tasty Pixel";
TargetAttributes = {
4CDCACBB1CA25AA8008AAEF1 = {
Expand Down Expand Up @@ -339,6 +339,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.atastypixel.TAAESample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "TAAESample/TAAESample-Bridging-Header.h";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -353,6 +354,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.atastypixel.TAAESample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "TAAESample/TAAESample-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
12 changes: 6 additions & 6 deletions TAAESample/Classes/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var audio: AEAudioController?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.audio = AEAudioController();
do {
try self.audio!.start();
Expand All @@ -30,25 +30,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
20 changes: 10 additions & 10 deletions TAAESample/Classes/PlayerButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PlayerButton: UIView {

var image: UIImage? {
willSet {
imageLayer.contents = newValue?.CGImage
imageLayer.contents = newValue?.cgImage
}
}

Expand All @@ -27,7 +27,7 @@ class PlayerButton: UIView {
let angle = positionForTime(CACurrentMediaTime(), speed: rotateSpeed)
offset = angle
imageLayer.transform = CATransform3DMakeRotation(CGFloat(angle), 0.0, 0.0, 1.0)
imageLayer.removeAnimationForKey(AnimationKey)
imageLayer.removeAnimation(forKey: AnimationKey)
rotateAnimation = nil
}

Expand All @@ -37,7 +37,7 @@ class PlayerButton: UIView {
animation.duration = 60.0 / fabs(newValue);
animation.repeatCount = Float.infinity
animation.fillMode = kCAFillModeForwards
imageLayer.addAnimation(animation, forKey: AnimationKey)
imageLayer.add(animation, forKey: AnimationKey)
startTime = CACurrentMediaTime()
rotateAnimation = animation
}
Expand All @@ -55,14 +55,14 @@ class PlayerButton: UIView {
layer.addSublayer(imageLayer)
imageLayer.frame = layer.bounds
imageLayer.contentsGravity = kCAGravityCenter
imageLayer.contentsScale = UIScreen.mainScreen().scale
imageLayer.contentsScale = UIScreen.main().scale

let highlight = UIImageView(image: UIImage(named: "Vinyl Highlight and Shadow"))
self.addSubview(highlight)
self.addConstraint(NSLayoutConstraint(item: highlight, attribute: NSLayoutAttribute.CenterX,
relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0))
self.addConstraint(NSLayoutConstraint(item: highlight, attribute: NSLayoutAttribute.CenterY,
relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
self.addConstraint(NSLayoutConstraint(item: highlight, attribute: NSLayoutAttribute.centerX,
relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.centerX, multiplier: 1, constant: 0))
self.addConstraint(NSLayoutConstraint(item: highlight, attribute: NSLayoutAttribute.centerY,
relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.centerY, multiplier: 1, constant: 0))
}

override func intrinsicContentSize() -> CGSize {
Expand All @@ -74,7 +74,7 @@ class PlayerButton: UIView {
imageLayer.frame = layer.bounds
}

private func positionForTime(time: CFTimeInterval, speed: Double) -> Double {
private func positionForTime(_ time: CFTimeInterval, speed: Double) -> Double {
return offset + ((time - startTime) / (60.0 / speed)) * 2.0*M_PI;
}
}
}
30 changes: 15 additions & 15 deletions TAAESample/Classes/TriggerGestureRecognizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ import UIKit.UIGestureRecognizerSubclass

class TriggerGestureRecognizer : UIGestureRecognizer {
var pressure: Double = 0
private var location: CGPoint = CGPointZero
private var location: CGPoint = CGPoint.zero

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent) {
self.state = UIGestureRecognizerState.Began
location = touches.first!.locationInView(nil)
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
self.state = UIGestureRecognizerState.began
location = touches.first!.location(in: nil)
pressure = Double(touches.first!.force / touches.first!.maximumPossibleForce)
}

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent) {
self.state = UIGestureRecognizerState.Changed
location = touches.first!.locationInView(nil)
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
self.state = UIGestureRecognizerState.changed
location = touches.first!.location(in: nil)
pressure = Double(touches.first!.force / touches.first!.maximumPossibleForce)
}

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent) {
self.state = UIGestureRecognizerState.Ended
location = touches.first!.locationInView(nil)
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) {
self.state = UIGestureRecognizerState.ended
location = touches.first!.location(in: nil)
}

override func touchesCancelled(touches: Set<UITouch>, withEvent event: UIEvent) {
self.state = UIGestureRecognizerState.Cancelled
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent) {
self.state = UIGestureRecognizerState.cancelled
}

override func locationInView(view: UIView?) -> CGPoint {
override func location(in view: UIView?) -> CGPoint {
if let view = view {
return view.convertPoint(location, fromView: nil)
return view.convert(location, from: nil)
} else {
return location
}
}
}
}
Loading

0 comments on commit c4dab16

Please sign in to comment.