Skip to content

Commit

Permalink
- movementHandler is now called only after the movement is initiated …
Browse files Browse the repository at this point in the history
…by the user

- PieSliceView background color property added
  • Loading branch information
scihant committed Oct 18, 2016
1 parent 43eeeb8 commit 56c97bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
11 changes: 6 additions & 5 deletions CTPanoramaView/CTPanoramaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,14 @@ import ImageIO

private func resetCameraAngles() {
cameraNode.eulerAngles = SCNVector3Make(0, 0, 0)
self.reportMovement(0, xFov.toRadians())
self.reportMovement(0, xFov.toRadians(), callHandler: false)
}

private func reportMovement(_ rotationAngle: CGFloat, _ fieldOfViewAngle: CGFloat) {
private func reportMovement(_ rotationAngle: CGFloat, _ fieldOfViewAngle: CGFloat, callHandler: Bool = true) {
radar?.updateUI(rotationAngle: rotationAngle, fieldOfViewAngle: fieldOfViewAngle)
movementHandler?(rotationAngle, fieldOfViewAngle)
if callHandler {
movementHandler?(rotationAngle, fieldOfViewAngle)
}
}

// MARK: Gesture handling
Expand Down Expand Up @@ -266,9 +268,8 @@ import ImageIO
super.layoutSubviews()
if bounds.size.width != prevBounds.size.width || bounds.size.height != prevBounds.size.height {
sceneView.setNeedsDisplay()
reportMovement(CGFloat(-cameraNode.eulerAngles.y), xFov.toRadians())
reportMovement(CGFloat(-cameraNode.eulerAngles.y), xFov.toRadians(), callHandler: false)
}

}
}

Expand Down
15 changes: 12 additions & 3 deletions CTPanoramaView/CTPieSliceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

@IBDesignable @objc public class CTPieSliceView: UIView {

@IBInspectable var sliceAngle: CGFloat = .pi/2 {
didSet { setNeedsDisplay() }
}
Expand All @@ -18,7 +18,11 @@ import UIKit
didSet { setNeedsDisplay() }
}

@IBInspectable var outerRingColor: UIColor = .gray {
@IBInspectable var outerRingColor: UIColor = .green {
didSet { setNeedsDisplay() }
}

@IBInspectable var bgColor: UIColor = .black {
didSet { setNeedsDisplay() }
}

Expand Down Expand Up @@ -46,6 +50,11 @@ import UIKit

guard let ctx = UIGraphicsGetCurrentContext() else {return}

// Draw the background
ctx.addEllipse(in: bounds)
ctx.setFillColor(bgColor.cgColor)
ctx.fillPath()

// Draw the outer ring
ctx.addEllipse(in: bounds.insetBy(dx: 2, dy: 2))
ctx.setStrokeColor(outerRingColor.cgColor)
Expand All @@ -57,7 +66,7 @@ import UIKit
let startAngle = -(.pi/2 + sliceAngle/2)
let endAngle = startAngle + sliceAngle
let arcStartPoint = CGPoint(x: localCenter.x + radius*cos(startAngle), y: localCenter.y + radius*sin(startAngle))

// Draw the inner slice
ctx.beginPath()
ctx.move(to: localCenter)
Expand Down

0 comments on commit 56c97bf

Please sign in to comment.