1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-09-11 13:15:35 +03:00

Example project updated to swift 2.3

This commit is contained in:
Viktor Sukochev 2016-09-20 18:35:55 +06:00
parent 1198cf5e1a
commit d28d14180e
13 changed files with 76 additions and 75 deletions

View File

@ -307,6 +307,7 @@
B02E75EC1C16104900D1971D = {
CreatedOnToolsVersion = 7.1.1;
DevelopmentTeam = 7DJJE3E4M9;
LastSwiftMigration = 0800;
};
};
};
@ -409,7 +410,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
@ -554,6 +555,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.exyte.Example.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 2.3;
};
name = Debug;
};
@ -570,6 +572,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.exyte.Example.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 2.3;
};
name = Release;
};

View File

@ -2,7 +2,7 @@ import UIKit
class AnimationsExampleController: UIViewController {
@IBOutlet var animView: AnimationsView?
var animView: AnimationsView?
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

View File

@ -54,12 +54,13 @@ class AnimationsView: MacawView {
}
for i in 0 ... (n - 1) {
arc4random()
// Node
let circle = Circle(cx: r, cy: r, r: r)
let shape = Shape(
form: circle,
fill: [Color.red, Color.green, Color.blue, Color.yellow, Color.olive, Color.purple][Int(rand() % 6)]
fill: [Color.red, Color.green, Color.blue, Color.yellow, Color.olive, Color.purple][Int(arc4random() % 6)]
)
let ballGroup = Group(contents: [shape])
@ -67,8 +68,8 @@ class AnimationsView: MacawView {
// Animation
let velocity = Point(
x: -0.5 * speed + speed * Double(rand() % 1000) / 1000.0,
y: -0.5 * speed + speed * Double(rand() % 1000) / 1000.0)
x: -0.5 * speed + speed * Double(arc4random() % 1000) / 1000.0,
y: -0.5 * speed + speed * Double(arc4random() % 1000) / 1000.0)
velocities.append(velocity)
positions.append(Point(x: 0.0, y: 0.0))

View File

@ -3,7 +3,7 @@ import UIKit
import Macaw
class ModelListenersExampleController: UIViewController {
@IBOutlet weak var macawView: RectShapeView!
weak var macawView: RectShapeView!
@IBOutlet weak var heightStepper: UIStepper!
@IBOutlet weak var widthSteppter: UIStepper!

View File

@ -1,7 +1,7 @@
import UIKit
class PathExampleController: UIViewController {
@IBOutlet var sceneView: PathExampleView?
var sceneView: PathExampleView?
@IBOutlet var slider: UISlider?
override func viewDidAppear(animated: Bool) {

View File

@ -2,4 +2,4 @@ use_frameworks!
target 'Example' do
pod 'Macaw', :path => '../'
end
end

View File

@ -1,10 +1,8 @@
PODS:
- Macaw (0.1.0):
- RxSwift
- Swift-CAAnimation-Closure (~> 1.0)
- RxSwift (~> 2.0s)
- SWXMLHash (~> 2.3.0)
- RxSwift (2.6.0)
- Swift-CAAnimation-Closure (1.4)
- SWXMLHash (2.3.2)
DEPENDENCIES:
@ -15,11 +13,10 @@ EXTERNAL SOURCES:
:path: ../
SPEC CHECKSUMS:
Macaw: f440797f9d71b878de88f489b6e9f9aee0ba6869
Macaw: 6d8c002627caf979148fd395770caf12112ecc2b
RxSwift: 77f3a0b15324baa7a1c9bfa9f199648a82424e26
Swift-CAAnimation-Closure: 9229ece23497fe8c073587ac63f14e74b64f483a
SWXMLHash: 2f8c49af765718ad56020c4f875ec3ff22612f06
PODFILE CHECKSUM: 228ebdda766cd7e558e36c929c03097c7aedb2ed
PODFILE CHECKSUM: 2b27ba53c0326bad26fb61b116044cf08cdac46d
COCOAPODS: 1.0.1
COCOAPODS: 1.1.0.rc.2

View File

@ -28,6 +28,7 @@ Pod::Spec.new do |s|
s.platform = :ios, '8.0'
s.requires_arc = true
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '2.3' }
s.source_files = [
'Source/*.swift',
@ -57,6 +58,5 @@ Pod::Spec.new do |s|
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
s.dependency 'SWXMLHash', '~> 2.3.0'
s.dependency 'RxSwift'
s.dependency 'Swift-CAAnimation-Closure', '~> 1.0'
s.dependency 'RxSwift', '~> 2.0s '
end

View File

@ -26,11 +26,11 @@ class GroupRenderer: NodeRenderer {
override func doRender(force: Bool, opacity: Double) {
renderers.forEach { renderer in
CGContextSaveGState(ctx.cgContext)
CGContextConcatCTM(ctx.cgContext, RenderUtils.mapTransform(renderer.node().place))
CGContextSaveGState(ctx.cgContext!)
CGContextConcatCTM(ctx.cgContext!, RenderUtils.mapTransform(renderer.node().place))
setClip(renderer.node())
renderer.render(force, opacity: renderer.node().opacity * opacity)
CGContextRestoreGState(ctx.cgContext)
CGContextRestoreGState(ctx.cgContext!)
}
}
@ -38,13 +38,13 @@ class GroupRenderer: NodeRenderer {
var touchedShapes = [Shape]()
renderers.forEach { renderer in
if let inverted = renderer.node().place.invert() {
CGContextSaveGState(ctx.cgContext)
CGContextConcatCTM(ctx.cgContext, RenderUtils.mapTransform(renderer.node().place))
CGContextSaveGState(ctx.cgContext!)
CGContextConcatCTM(ctx.cgContext!, RenderUtils.mapTransform(renderer.node().place))
let translatedLocation = CGPointApplyAffineTransform(location, RenderUtils.mapTransform(inverted))
setClip(renderer.node())
let offsetLocation = CGPoint(x: translatedLocation.x, y: translatedLocation.y)
touchedShapes.appendContentsOf(renderer.detectTouches(offsetLocation))
CGContextRestoreGState(ctx.cgContext)
CGContextRestoreGState(ctx.cgContext!)
}
}
@ -61,7 +61,7 @@ class GroupRenderer: NodeRenderer {
// TODO: path support
func setClip(node: Node) {
if let rect = node.clip as? Rect {
CGContextClipToRect(ctx.cgContext, CGRect(x: rect.x, y: rect.y, width: rect.w, height: rect.h))
CGContextClipToRect(ctx.cgContext!, CGRect(x: rect.x, y: rect.y, width: rect.w, height: rect.h))
}
}

View File

@ -44,17 +44,17 @@ class ImageRenderer: NodeRenderer {
rect = calculateMeetAspectRatio(image, size: imageSize)
case AspectRatio.slice:
rect = calculateSliceAspectRatio(image, size: imageSize)
CGContextClipToRect(ctx.cgContext, CGRectMake(0, 0, w, h))
CGContextClipToRect(ctx.cgContext!, CGRectMake(0, 0, w, h))
default:
rect = CGRectMake(0, 0, w, h)
}
}
CGContextScaleCTM(ctx.cgContext, 1.0, -1.0)
CGContextTranslateCTM(ctx.cgContext, 0.0, -1.0 * rect.height)
CGContextScaleCTM(ctx.cgContext!, 1.0, -1.0)
CGContextTranslateCTM(ctx.cgContext!, 0.0, -1.0 * rect.height)
CGContextSetAlpha(ctx.cgContext, CGFloat(opacity))
CGContextDrawImage(ctx.cgContext, rect, uiimage.CGImage)
CGContextSetAlpha(ctx.cgContext!, CGFloat(opacity))
CGContextDrawImage(ctx.cgContext!, rect, uiimage.CGImage!)
}
}
@ -137,4 +137,4 @@ class ImageRenderer: NodeRenderer {
}
return CGRectMake(srcX, srcY, totalW, totalH)
}
}
}

View File

@ -424,10 +424,10 @@ class ShapeRenderer: NodeRenderer {
}
if let fill = fill, stroke = stroke {
let path = CGContextCopyPath(ctx)
let path = CGContextCopyPath(ctx!)
setFill(fill, ctx: ctx, opacity: opacity)
if stroke.fill is Gradient && !(fill is Gradient) {
CGContextDrawPath(ctx, .Fill)
CGContextDrawPath(ctx!, .Fill)
}
drawWithStroke(stroke, ctx: ctx, opacity: opacity, shouldStrokePath: shouldStrokePath, path: path, mode: .FillStroke)
return
@ -435,7 +435,7 @@ class ShapeRenderer: NodeRenderer {
if let fill = fill {
setFill(fill, ctx: ctx, opacity: opacity)
CGContextDrawPath(ctx, .Fill)
CGContextDrawPath(ctx!, .Fill)
return
}
@ -444,9 +444,9 @@ class ShapeRenderer: NodeRenderer {
return
}
CGContextSetLineWidth(ctx, 2.0)
CGContextSetStrokeColorWithColor(ctx, UIColor.blackColor().CGColor)
CGContextDrawPath(ctx, .Stroke)
CGContextSetLineWidth(ctx!, 2.0)
CGContextSetStrokeColorWithColor(ctx!, UIColor.blackColor().CGColor)
CGContextDrawPath(ctx!, .Stroke)
}
private func setFill(fill: Fill?, ctx: CGContext?, opacity: Double) {
@ -455,7 +455,7 @@ class ShapeRenderer: NodeRenderer {
}
if let fillColor = fill as? Color {
let color = RenderUtils.applyOpacity(fillColor, opacity: opacity)
CGContextSetFillColorWithColor(ctx, RenderUtils.mapColor(color))
CGContextSetFillColorWithColor(ctx!, RenderUtils.mapColor(color))
} else if let gradient = fill as? Gradient {
drawGradient(gradient, ctx: ctx, opacity: opacity)
} else {
@ -465,7 +465,7 @@ class ShapeRenderer: NodeRenderer {
private func drawWithStroke(stroke: Stroke, ctx: CGContext?, opacity: Double, shouldStrokePath: Bool = false, path: CGPath? = nil, mode: CGPathDrawingMode) {
if let path = path where shouldStrokePath {
CGContextAddPath(ctx, path)
CGContextAddPath(ctx!, path)
}
setStrokeAttributes(stroke, ctx: ctx)
@ -476,20 +476,20 @@ class ShapeRenderer: NodeRenderer {
colorStroke(stroke, ctx: ctx, opacity: opacity)
}
if shouldStrokePath {
CGContextStrokePath(ctx)
CGContextStrokePath(ctx!)
} else {
CGContextDrawPath(ctx, mode)
CGContextDrawPath(ctx!, mode)
}
}
private func setStrokeAttributes(stroke: Stroke, ctx: CGContext?) {
CGContextSetLineWidth(ctx, CGFloat(stroke.width))
CGContextSetLineJoin(ctx, RenderUtils.mapLineJoin(stroke.join))
CGContextSetLineCap(ctx, RenderUtils.mapLineCap(stroke.cap))
CGContextSetLineWidth(ctx!, CGFloat(stroke.width))
CGContextSetLineJoin(ctx!, RenderUtils.mapLineJoin(stroke.join))
CGContextSetLineCap(ctx!, RenderUtils.mapLineCap(stroke.cap))
let dashes = stroke.dashes
if !dashes.isEmpty {
let dashPointer = RenderUtils.mapDash(dashes)
CGContextSetLineDash(ctx, 0, dashPointer, dashes.count)
CGContextSetLineDash(ctx!, 0, dashPointer, dashes.count)
dashPointer.dealloc(dashes.count)
}
}
@ -499,19 +499,19 @@ class ShapeRenderer: NodeRenderer {
return
}
let color = RenderUtils.applyOpacity(strokeColor, opacity: opacity)
CGContextSetStrokeColorWithColor(ctx, RenderUtils.mapColor(color))
CGContextSetStrokeColorWithColor(ctx!, RenderUtils.mapColor(color))
}
private func gradientStroke(stroke: Stroke, ctx: CGContext?, opacity: Double) {
guard let gradient = stroke.fill as? Gradient else {
return
}
CGContextReplacePathWithStrokedPath(ctx)
CGContextReplacePathWithStrokedPath(ctx!)
drawGradient(gradient, ctx: ctx, opacity: opacity)
}
private func drawGradient(gradient: Gradient, ctx: CGContext?, opacity: Double) {
CGContextSaveGState(ctx)
CGContextSaveGState(ctx!)
var colors: [CGColor] = []
var stops: [CGFloat] = []
for stop in gradient.stops {
@ -524,19 +524,19 @@ class ShapeRenderer: NodeRenderer {
var start = CGPointMake(CGFloat(gradient.x1), CGFloat(gradient.y1))
var end = CGPointMake(CGFloat(gradient.x2), CGFloat(gradient.y2))
if !gradient.userSpace {
let bounds = CGContextGetPathBoundingBox(ctx)
let bounds = CGContextGetPathBoundingBox(ctx!)
start = CGPointMake(start.x * bounds.width + bounds.minX, start.y * bounds.height + bounds.minY)
end = CGPointMake(end.x * bounds.width + bounds.minX, end.y * bounds.height + bounds.minY)
}
CGContextClip(ctx)
CGContextClip(ctx!)
let cgGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), colors, stops)
CGContextDrawLinearGradient(ctx, cgGradient, start, end, [.DrawsAfterEndLocation, .DrawsBeforeStartLocation])
CGContextDrawLinearGradient(ctx!, cgGradient!, start, end, [.DrawsAfterEndLocation, .DrawsBeforeStartLocation])
} else if let gradient = gradient as? RadialGradient {
var innerCenter = CGPointMake(CGFloat(gradient.fx), CGFloat(gradient.fy))
var outerCenter = CGPointMake(CGFloat(gradient.cx), CGFloat(gradient.cy))
var radius = CGFloat(gradient.r)
if !gradient.userSpace {
var bounds = CGContextGetPathBoundingBox(ctx)
var bounds = CGContextGetPathBoundingBox(ctx!)
var scaleX: CGFloat = 1
var scaleY: CGFloat = 1
if bounds.width > bounds.height {
@ -544,18 +544,18 @@ class ShapeRenderer: NodeRenderer {
} else {
scaleX = bounds.width / bounds.height
}
CGContextScaleCTM(ctx, scaleX, scaleY)
bounds = CGContextGetPathBoundingBox(ctx)
CGContextScaleCTM(ctx!, scaleX, scaleY)
bounds = CGContextGetPathBoundingBox(ctx!)
innerCenter = CGPointMake(innerCenter.x * bounds.width + bounds.minX, innerCenter.y * bounds.height + bounds.minY)
outerCenter = CGPointMake(outerCenter.x * bounds.width + bounds.minX, outerCenter.y * bounds.height + bounds.minY)
radius = min(radius * bounds.width, radius * bounds.height)
}
CGContextClip(ctx)
CGContextClip(ctx!)
let cgGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), colors, stops)
CGContextDrawRadialGradient(ctx, cgGradient, innerCenter, 0, outerCenter, radius, [.DrawsAfterEndLocation, .DrawsBeforeStartLocation])
CGContextDrawRadialGradient(ctx!, cgGradient!, innerCenter, 0, outerCenter, radius, [.DrawsAfterEndLocation, .DrawsBeforeStartLocation])
}
CGContextRestoreGState(ctx)
CGContextRestoreGState(ctx!)
}
}

View File

@ -9,7 +9,7 @@
import QuartzCore
/// CAAnimation Delegation class implementation
class CAAnimationDelegate: NSObject {
class CAAnimationDelegateImpl:NSObject, CAAnimationDelegate {
/// start: A block (closure) object to be executed when the animation starts. This block has no return value and takes no argument.
var start: (() -> Void)?
@ -35,7 +35,7 @@ class CAAnimationDelegate: NSObject {
- parameter theAnimation: the animation about to start
*/
override func animationDidStart(theAnimation: CAAnimation) {
func animationDidStart(theAnimation: CAAnimation) {
start?()
if animating != nil {
animationDuration = theAnimation.duration
@ -50,7 +50,7 @@ class CAAnimationDelegate: NSObject {
- parameter theAnimation: the animation about to end
- parameter finished: A Boolean value indicates whether or not the animations actually finished.
*/
override func animationDidStop(theAnimation: CAAnimation, finished: Bool) {
func animationDidStop(theAnimation: CAAnimation, finished: Bool) {
completion?(finished)
animatingTimer?.invalidate()
}
@ -72,17 +72,17 @@ public extension CAAnimation {
/// A block (closure) object to be executed when the animation starts. This block has no return value and takes no argument.
public var start: (() -> Void)? {
set {
if let animationDelegate = delegate as? CAAnimationDelegate {
if let animationDelegate = delegate as? CAAnimationDelegateImpl {
animationDelegate.start = newValue
} else {
let animationDelegate = CAAnimationDelegate()
let animationDelegate = CAAnimationDelegateImpl()
animationDelegate.start = newValue
delegate = animationDelegate
}
}
get {
if let animationDelegate = delegate as? CAAnimationDelegate {
if let animationDelegate = delegate as? CAAnimationDelegateImpl {
return animationDelegate.start
}
@ -93,17 +93,17 @@ public extension CAAnimation {
/// A block (closure) object to be executed when the animation ends. This block has no return value and takes a single Boolean argument that indicates whether or not the animations actually finished.
public var completion: ((Bool) -> Void)? {
set {
if let animationDelegate = delegate as? CAAnimationDelegate {
if let animationDelegate = delegate as? CAAnimationDelegateImpl {
animationDelegate.completion = newValue
} else {
let animationDelegate = CAAnimationDelegate()
let animationDelegate = CAAnimationDelegateImpl()
animationDelegate.completion = newValue
delegate = animationDelegate
}
}
get {
if let animationDelegate = delegate as? CAAnimationDelegate {
if let animationDelegate = delegate as? CAAnimationDelegateImpl {
return animationDelegate.completion
}
@ -114,17 +114,17 @@ public extension CAAnimation {
/// A block (closure) object to be executed when the animation is animating. This block has no return value and takes a single CGFloat argument that indicates the progress of the animation (From 0 ..< 1)
public var animating: ((CGFloat) -> Void)? {
set {
if let animationDelegate = delegate as? CAAnimationDelegate {
if let animationDelegate = delegate as? CAAnimationDelegateImpl {
animationDelegate.animating = newValue
} else {
let animationDelegate = CAAnimationDelegate()
let animationDelegate = CAAnimationDelegateImpl()
animationDelegate.animating = newValue
delegate = animationDelegate
}
}
get {
if let animationDelegate = delegate as? CAAnimationDelegate {
if let animationDelegate = delegate as? CAAnimationDelegateImpl {
return animationDelegate.animating
}

View File

@ -89,10 +89,10 @@ public class MacawView: UIView {
override public func drawRect(rect: CGRect) {
self.context.cgContext = UIGraphicsGetCurrentContext()
CGContextSaveGState(self.context.cgContext)
CGContextConcatCTM(self.context.cgContext, RenderUtils.mapTransform(node.place))
CGContextSaveGState(self.context.cgContext!)
CGContextConcatCTM(self.context.cgContext!, RenderUtils.mapTransform(node.place))
renderer?.render(false, opacity: node.opacity)
CGContextRestoreGState(self.context.cgContext)
CGContextRestoreGState(self.context.cgContext!)
}
public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
@ -102,10 +102,10 @@ public class MacawView: UIView {
let location = touch.locationInView(self)
let translatedLocation = CGPointApplyAffineTransform(location, RenderUtils.mapTransform(inverted))
let offsetLocation = CGPoint(x: translatedLocation.x, y: translatedLocation.y)
CGContextSaveGState(self.context.cgContext)
CGContextConcatCTM(self.context.cgContext, RenderUtils.mapTransform(node.place))
CGContextSaveGState(self.context.cgContext!)
CGContextConcatCTM(self.context.cgContext!, RenderUtils.mapTransform(node.place))
let shapes = renderer?.detectTouches(offsetLocation)
CGContextRestoreGState(self.context.cgContext)
CGContextRestoreGState(self.context.cgContext!)
self.selectedShape = shapes?.first
if let shape = self.selectedShape {
shape.onTap.onNext(TapEvent(location: Point(x: Double(offsetLocation.x), y: Double(offsetLocation.y))))
@ -148,4 +148,4 @@ public class MacawView: UIView {
nodesMap.remove(node)
}
}
}