Skip to content

Commit

Permalink
Updated to support Swift 4.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
poetmountain committed Sep 22, 2017
1 parent 4419cce commit 49745e4
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 63 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 1.2.0
Support for Swift 4.0.

#### 1.1.1
Fixes for compiler warnings and deprecations.

Expand Down
2 changes: 1 addition & 1 deletion Classes/PhysicsMotion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ public class PhysicsMotion: Moveable, Additive, TempoDriven, PropertyDataDelegat
removePhysicsTimer()
}
physicsTimer = DispatchSource.makeTimerSource(flags: DispatchSource.TimerFlags(rawValue: UInt(0)), queue: DispatchQueue.global(qos: .userInteractive) )
physicsTimer?.scheduleRepeating(deadline: DispatchTime.now(), interval: physicsTimerInterval, leeway: DispatchTimeInterval.milliseconds(1))
physicsTimer?.schedule(deadline: DispatchTime.now(), repeating: physicsTimerInterval, leeway: DispatchTimeInterval.milliseconds(1))

physicsTimer?.setEventHandler(handler: {
[weak self] in
Expand Down
26 changes: 22 additions & 4 deletions Examples/MotionExamples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0830;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Poet & Mountain, LLC";
TargetAttributes = {
8BB379D31CFFA17D00A35AFD = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
ProvisioningStyle = Manual;
};
};
Expand Down Expand Up @@ -335,14 +335,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -371,6 +377,8 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -383,14 +391,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand All @@ -411,6 +425,8 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -423,7 +439,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.poetmountain.MotionExamples;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -435,7 +452,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.poetmountain.MotionExamples;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
8 changes: 4 additions & 4 deletions Examples/MotionExamples/ButtonsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,19 @@ public class ButtonsView: UIView {



func start() {
@objc func start() {
delegate?.didStart()
}

func stop() {
@objc func stop() {
delegate?.didStop()
}

func pause() {
@objc func pause() {
delegate?.didPause()
}

func resume() {
@objc func resume() {
delegate?.didResume()
}

Expand Down
31 changes: 26 additions & 5 deletions Examples/MotionExamples/Classes/AdditiveViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ public class AdditiveViewController: UIViewController, ButtonsViewDelegate {
tapRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(viewTappedHandler))
view.addGestureRecognizer(tapRecognizer)

var margins : UILayoutGuide
if #available(iOS 11.0, *) {
margins = view.safeAreaLayoutGuide
} else {
margins = view.layoutMarginsGuide
}

// setup motion
let expanded_amount = Double(view.layoutMarginsGuide.layoutFrame.size.height) * 1.2
let expanded_amount = Double(margins.layoutFrame.size.height) * 1.2
let normal_amount = 40.0

let change_color = Motion(target: circle,
Expand Down Expand Up @@ -137,7 +143,13 @@ public class AdditiveViewController: UIViewController, ButtonsViewDelegate {

private func setupUI() {
view.backgroundColor = UIColor.white
let margins = view.layoutMarginsGuide

var margins : UILayoutGuide
if #available(iOS 11.0, *) {
margins = view.safeAreaLayoutGuide
} else {
margins = view.layoutMarginsGuide
}


let label = UILabel.init(frame: CGRect.zero)
Expand All @@ -155,9 +167,18 @@ public class AdditiveViewController: UIViewController, ButtonsViewDelegate {
circle.layer.cornerRadius = w * 0.5
self.view.addSubview(circle)

var y_offset : CGFloat = 0.0

if #available(iOS 11.0, *) {
y_offset = CGFloat(view.safeAreaInsets.top)

} else {
y_offset = CGFloat(topLayoutGuide.length)
}

circle.translatesAutoresizingMaskIntoConstraints = false
circle.centerXAnchor.constraint(equalTo: margins.centerXAnchor).isActive = true
circle.centerYAnchor.constraint(equalTo: margins.centerYAnchor).isActive = true
circle.centerXAnchor.constraint(equalTo: margins.centerXAnchor, constant: 0.0).isActive = true
circle.centerYAnchor.constraint(equalTo: margins.centerYAnchor, constant: -y_offset).isActive = true

let circle_height = circle.heightAnchor.constraint(equalToConstant: 40.0)
circle_height.isActive = true
Expand Down Expand Up @@ -188,7 +209,7 @@ public class AdditiveViewController: UIViewController, ButtonsViewDelegate {



func viewTappedHandler(_ gesture: UITapGestureRecognizer) {
@objc func viewTappedHandler(_ gesture: UITapGestureRecognizer) {

if (gesture.state != UIGestureRecognizerState.ended) {
return;
Expand Down
19 changes: 16 additions & 3 deletions Examples/MotionExamples/Classes/BasicMotionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,20 @@ public class BasicMotionViewController: UIViewController, ButtonsViewDelegate {

private func setupUI() {
view.backgroundColor = UIColor.white
let margins = view.layoutMarginsGuide

var margins : UILayoutGuide
if #available(iOS 11.0, *) {
margins = view.safeAreaLayoutGuide
} else {
margins = topLayoutGuide as! UILayoutGuide
}

var top_anchor: NSLayoutYAxisAnchor
if #available(iOS 11.0, *) {
top_anchor = margins.topAnchor
} else {
top_anchor = margins.bottomAnchor
}

buttonsView = ButtonsView.init(frame: CGRect.zero)
view.addSubview(buttonsView)
Expand All @@ -95,9 +108,9 @@ public class BasicMotionViewController: UIViewController, ButtonsViewDelegate {
self.view.addSubview(motionView)
motionView.translatesAutoresizingMaskIntoConstraints = false

xConstraint = motionView.leadingAnchor.constraint(equalTo: margins.leadingAnchor, constant: 0.0)
xConstraint = motionView.leadingAnchor.constraint(equalTo: margins.leadingAnchor, constant: 20.0)
xConstraint.isActive = true
motionView.topAnchor.constraint(equalTo: margins.topAnchor, constant: topLayoutGuide.length+20.0).isActive = true
motionView.topAnchor.constraint(equalTo: top_anchor, constant: 20.0).isActive = true
motionView.widthAnchor.constraint(equalToConstant: 40.0).isActive = true
motionView.heightAnchor.constraint(equalToConstant: 40.0).isActive = true

Expand Down
47 changes: 37 additions & 10 deletions Examples/MotionExamples/Classes/DynamicViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public class DynamicViewController: UIViewController, ButtonsViewDelegate {



public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
public override func viewWillAppear(_ animated: Bool) {

super.viewWillAppear(animated)

if (!createdUI) {
setupUI()
Expand Down Expand Up @@ -68,8 +69,15 @@ public class DynamicViewController: UIViewController, ButtonsViewDelegate {

private func setupUI() {
view.backgroundColor = UIColor.white
let margins = view.layoutMarginsGuide

var margins : UILayoutGuide
let top_offset : CGFloat = 20.0

if #available(iOS 11.0, *) {
margins = view.safeAreaLayoutGuide
} else {
margins = topLayoutGuide as! UILayoutGuide
}

let label = UILabel.init(frame: CGRect.zero)
label.font = UIFont.systemFont(ofSize: 12.0)
Expand All @@ -85,11 +93,20 @@ public class DynamicViewController: UIViewController, ButtonsViewDelegate {
circle.layer.masksToBounds = true
circle.layer.cornerRadius = w * 0.5
self.view.addSubview(circle)


var top_anchor: NSLayoutYAxisAnchor
if #available(iOS 11.0, *) {
top_anchor = margins.topAnchor
} else {
top_anchor = margins.bottomAnchor
}

circle.translatesAutoresizingMaskIntoConstraints = false
let circle_x = circle.centerXAnchor.constraint(equalTo: margins.leadingAnchor, constant: 20.0)
let circle_x = circle.centerXAnchor.constraint(equalTo: margins.leadingAnchor, constant: 48.0)
circle_x.isActive = true
let circle_y = circle.centerYAnchor.constraint(equalTo: margins.topAnchor, constant: topLayoutGuide.length+40.0)

let circle_y = circle.topAnchor.constraint(equalTo: top_anchor, constant: top_offset)
circle_y.isActive = true

circle.heightAnchor.constraint(equalToConstant: 40.0).isActive = true
Expand All @@ -99,8 +116,8 @@ public class DynamicViewController: UIViewController, ButtonsViewDelegate {
constraints["y"] = circle_y

label.translatesAutoresizingMaskIntoConstraints = false
label.leadingAnchor.constraint(equalTo: margins.leadingAnchor, constant: 50.0).isActive = true
label.centerYAnchor.constraint(equalTo: margins.topAnchor, constant: topLayoutGuide.length+40.0).isActive = true
label.leadingAnchor.constraint(equalTo: margins.leadingAnchor, constant: 80.0).isActive = true
label.firstBaselineAnchor.constraint(equalTo: top_anchor, constant: top_offset).isActive = true
label.widthAnchor.constraint(equalToConstant: 220.0).isActive = true
label.heightAnchor.constraint(equalToConstant: 60.0).isActive = true

Expand All @@ -119,25 +136,35 @@ public class DynamicViewController: UIViewController, ButtonsViewDelegate {



func viewTappedHandler(_ gesture: UITapGestureRecognizer) {
@objc func viewTappedHandler(_ gesture: UITapGestureRecognizer) {

if (gesture.state != UIGestureRecognizerState.ended) {
return;
}

let pt = gesture.location(in: self.view)
//print("gesture pt \(pt)")

var y_offset : CGFloat = 0.0

if #available(iOS 11.0, *) {
y_offset = CGFloat(view.safeAreaInsets.top) + 20.0

} else {
y_offset = CGFloat(topLayoutGuide.length) + 20.0
}

// setup new motion
let x = constraints["x"]!
let y = constraints["y"]!
let motion_x = Motion(target: x,
properties: [PropertyData(path: "constant", start: Double(x.constant), end: Double(pt.x-20.0))],
properties: [PropertyData(path: "constant", start: Double(x.constant), end: Double(pt.x))],
duration: 1.5,
easing: EasingQuadratic.easeInOut())
motion_x.additive = true

let motion_y = Motion(target: y,
properties: [PropertyData(path: "constant", start: Double(y.constant), end: Double(pt.y))],
properties: [PropertyData(path: "constant", start: Double(y.constant), end: Double(pt.y-y_offset))],
duration: 1.5,
easing: EasingQuadratic.easeInOut())
motion_y.additive = true
Expand Down
23 changes: 19 additions & 4 deletions Examples/MotionExamples/Classes/GroupMotionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ public class GroupMotionViewController: UIViewController, ButtonsViewDelegate {

private func setupUI() {
view.backgroundColor = UIColor.white
let margins = view.layoutMarginsGuide

var margins : UILayoutGuide
if #available(iOS 11.0, *) {
margins = view.safeAreaLayoutGuide
} else {
margins = topLayoutGuide as! UILayoutGuide
}

buttonsView = ButtonsView.init(frame: CGRect.zero)
view.addSubview(buttonsView)
Expand Down Expand Up @@ -124,14 +130,23 @@ public class GroupMotionViewController: UIViewController, ButtonsViewDelegate {
circle.translatesAutoresizingMaskIntoConstraints = false
circle2.translatesAutoresizingMaskIntoConstraints = false

let circle_x = circle.leadingAnchor.constraint(equalTo: margins.leadingAnchor, constant: 0.0)
let xoffset : CGFloat = 20.0

var top_anchor: NSLayoutYAxisAnchor
if #available(iOS 11.0, *) {
top_anchor = margins.topAnchor
} else {
top_anchor = margins.bottomAnchor
}

let circle_x = circle.leadingAnchor.constraint(equalTo: margins.leadingAnchor, constant: xoffset)
circle_x.isActive = true
let circle_y = circle.topAnchor.constraint(equalTo: margins.topAnchor, constant: topLayoutGuide.length+40.0)
let circle_y = circle.topAnchor.constraint(equalTo: top_anchor, constant: 20.0)
circle_y.isActive = true
circle.widthAnchor.constraint(equalToConstant: 40.0).isActive = true
circle.heightAnchor.constraint(equalToConstant: 40.0).isActive = true

let circle2_x = circle2.leadingAnchor.constraint(equalTo: margins.leadingAnchor, constant: 0.0)
let circle2_x = circle2.leadingAnchor.constraint(equalTo: margins.leadingAnchor, constant: xoffset)
circle2_x.isActive = true
circle2.topAnchor.constraint(equalTo: circle.layoutMarginsGuide.bottomAnchor, constant: 20.0).isActive = true
circle2.widthAnchor.constraint(equalToConstant: 40.0).isActive = true
Expand Down
Loading

0 comments on commit 49745e4

Please sign in to comment.