Skip to content

Commit

Permalink
Merge pull request #5 from fatalhck/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
fatalhck committed Nov 25, 2016
2 parents b133a2a + f3b1024 commit bdafadd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
1 change: 1 addition & 0 deletions Findr/Classes/FindrConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ internal func deltaAngle(_ angle1: Double, angle2: Double) -> Double
//MARK: FindrViewController Delegate
protocol FindrViewControllerDelegate {

func findrViewControllerUpdateAngleForAnnotation(findrViewController: FindrViewController,annotation: FindrAnnotation , angle: CGFloat)
func findrViewControllerFixedVerticalPositionForAnnotation(findrViewController: FindrViewController)-> CGFloat?
func findrViewControllerWillShowAnnotationView(findrViewController: FindrViewController, annotationView: FindrAnnotationView)
func findrViewControllerWillReloadAnnotations(findrViewController: FindrViewController, annotations: [FindrAnnotation])
Expand Down
4 changes: 1 addition & 3 deletions Findr/Classes/FindrTrackingManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ open class FindrTrackingManager: NSObject, CLLocationManagerDelegate
{
angle = atan2(-self.lastAcceleration.x, self.lastAcceleration.z)
}

angle += M_PI_2
angle = (self.pitchPrevious + angle) / 2.0
self.pitchPrevious = angle
Expand All @@ -295,9 +294,8 @@ open class FindrTrackingManager: NSObject, CLLocationManagerDelegate
// Simplified azimuth calculation
azimuth = radiansToDegrees(atan2(longitudeDistance, (latitudeDistance * Double(LAT_LON_FACTOR))))

// TODO: Não TIREI 40
azimuth += 180.0

return azimuth;
}

Expand Down
48 changes: 23 additions & 25 deletions Findr/Classes/FindrViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,13 @@ open class FindrViewController: UIViewController, FindrTrackingManagerDelegate

NotificationCenter.default.addObserver(self, selector: #selector(FindrViewController.locationNotification(_:)), name: NSNotification.Name(rawValue: "kNotificationLocationSet"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(FindrViewController.appWillEnterForeground(_:)), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(FindrViewController.appWillResignActive(_:)), name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
self.initialize()
}

/// Intended for use in subclasses, no need to call super
internal func initialize()
{

}

deinit
Expand Down Expand Up @@ -337,24 +336,30 @@ open class FindrViewController: UIViewController, FindrTrackingManagerDelegate
self.degreesPerScreen = (self.view.bounds.size.width / OVERLAY_VIEW_WIDTH) * 360.0
}

internal func appWillResignActive(_ notification: Notification){
// debugPrint(#function)
self.trackingManager.stopTracking()

}


internal func appWillEnterForeground(_ notification: Notification)
{
if(self.view.window != nil)
{
// Removing all from screen and restarting location manager.
for annotation in self.annotations
{
annotation.annotationView = nil
}

for annotationView in self.annotationViews
{
annotationView.removeFromSuperview()
}

self.annotationViews = []
shouldReloadAnnotations = true;
self.trackingManager.stopTracking()
// for annotation in self.annotations
// {
// annotation.annotationView = nil
// }
//
// for annotationView in self.annotationViews
// {
// annotationView.removeFromSuperview()
// }
//
// self.annotationViews = []
// shouldReloadAnnotations = true
self.trackingManager.startTracking()
}
}
Expand Down Expand Up @@ -512,7 +517,7 @@ open class FindrViewController: UIViewController, FindrTrackingManagerDelegate
{
//minor distance between two angles
let delta = deltaAngle(currentHeading, angle2: annotationView.annotation!.azimuth)

// debugPrint("delta = \(delta), degreesDelta = \(degreesDelta), currentHeading = \(currentHeading)")
if fabs(delta) < degreesDelta && annotationView.annotation!.verticalLevel <= self.maxVerticalLevel
{
// put head annotation on view
Expand All @@ -539,6 +544,8 @@ open class FindrViewController: UIViewController, FindrTrackingManagerDelegate
}
}
}
delegate?.findrViewControllerUpdateAngleForAnnotation(findrViewController: self, annotation: annotationView.annotation!, angle: CGFloat(delta) + 180)

}
}

Expand Down Expand Up @@ -576,7 +583,6 @@ open class FindrViewController: UIViewController, FindrTrackingManagerDelegate
let x = self.xPositionForAnnotationView(annotationView, heading: self.trackingManager.heading)
let y = self.yPositionForAnnotationView(annotationView)

print("x= \(x), y = \(y)")
annotationView.frame = CGRect(x: x, y: y, width: annotationView.bounds.size.width, height: annotationView.bounds.size.height)
}
}
Expand All @@ -585,10 +591,6 @@ open class FindrViewController: UIViewController, FindrTrackingManagerDelegate
{
if annotationView.annotation == nil { return 0 }

// if let fixedPosition = delegate?.findrViewControllerFixedPositionForAnnotation(findrViewController: self){
// return fixedPosition.x
// }

let annotation = annotationView.annotation!

// Azimuth
Expand Down Expand Up @@ -624,10 +626,6 @@ open class FindrViewController: UIViewController, FindrTrackingManagerDelegate
fileprivate func yPositionForAnnotationView(_ annotationView: FindrAnnotationView) -> CGFloat
{

// if let fixedPosition = delegate?.findrViewControllerFixedPositionForAnnotation(findrViewController: self){
// return fixedPosition.y
// }

var distanceInM = annotationView.annotation?.beaconDistance

let initialScale = 5.0
Expand Down

0 comments on commit bdafadd

Please sign in to comment.