This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)forwardInvocation:(NSInvocation *)invocation { | |
// check if method can return something | |
BOOL methodReturnSomething = (![[NSString stringWithCString:invocation.methodSignature.methodReturnType encoding:NSUTF8StringEncoding] isEqualToString:@"v"]); | |
// send invocation to the main delegate and use it's return value | |
if ([self.mainDelegate respondsToSelector:invocation.selector]) | |
[invocation invokeWithTarget:self.mainDelegate]; | |
// make another fake invocation with the same method signature and send the same messages to the other delegates (ignoring return values) | |
NSInvocation *targetInvocation = invocation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) layoutSubviews:(BOOL) aAnimated completion:(void (^)(void)) aCompletion { | |
void (^layoutBlock)(void) = ^void(void) { | |
static BOOL isScrollView; | |
static CGRect visibleRect; | |
static CGFloat currentOffset; | |
static CGRect idealFrame; | |
static CGRect subviewFrame; | |
visibleRect = CGRectMake(0.0f, self.contentOffset.y, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame)); | |
currentOffset = 0.0f; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static func resample(points: [StrokePoint], totalPoints: Int) -> [StrokePoint] { | |
var initialPoints = points | |
let interval = StrokePoint.pathLength(initialPoints) / Double(totalPoints - 1) | |
var totalLength: Double = 0.0 | |
var newPoints: [StrokePoint] = [points.first!] | |
for var i = 1; i < initialPoints.count; ++i { let currentLength = initialPoints[i-1].distanceTo(initialPoints[i]) if ( (totalLength+currentLength) >= interval) { | |
let qx = initialPoints[i-1].x + ((interval - totalLength) / currentLength) * (initialPoints[i].x - initialPoints[i-1].x) | |
let qy = initialPoints[i-1].y + ((interval - totalLength) / currentLength) * (initialPoints[i].y - initialPoints[i-1].y) | |
let q = StrokePoint(x: qx, y: qy) | |
newPoints.append(q) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static func indicativeAngle(points: [StrokePoint]) -> Double { | |
let centroid = StrokePoint.centroid(points) | |
return atan2(centroid.y - points.first!.y, centroid.x - points.first!.x) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static func rotate(points: [StrokePoint], byRadians radians: Double) -> [StrokePoint] { | |
let centroid = StrokePoint.centroid(points) | |
let cosvalue = cos(radians) | |
let sinvalue = sin(radians) | |
var newPoints: [StrokePoint] = [] | |
for point in points { | |
let qx = (point.x - centroid.x) * cosvalue - (point.y - centroid.y) * sinvalue + centroid.x | |
let qy = (point.x - centroid.x) * sinvalue + (point.y - centroid.y) * cosvalue + centroid.y | |
newPoints.append(StrokePoint(x: qx, y: qy)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static func scale(points: [StrokePoint], toSize size: Double) -> [StrokePoint] { | |
let boundingBox = StrokePoint.boundingBox(points) | |
var newPoints: [StrokePoint] = [] | |
for point in points { | |
let qx = point.x * (size / boundingBox.width) | |
let qy = point.y * (size / boundingBox.height) | |
newPoints.append(StrokePoint(x: qx, y: qy)) | |
} | |
return newPoints | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static func distanceAtBestAngle(points: [StrokePoint], strokeTemplate: [StrokePoint], var fromAngle: Double, var toAngle: Double, threshold: Double) -> Double { | |
var x1 = StrokeConsts.Phi * fromAngle + (1.0 - StrokeConsts.Phi) * toAngle | |
var f1 = StrokePoint.distanceAtAngle(points, strokeTemplate: strokeTemplate, radians: x1) | |
var x2 = (1.0 - StrokeConsts.Phi) * fromAngle + StrokeConsts.Phi * toAngle | |
var f2 = StrokePoint.distanceAtAngle(points, strokeTemplate: strokeTemplate, radians: x2) | |
while ( abs(toAngle-fromAngle) > threshold ) { | |
if f1 < f2 { | |
toAngle = x2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
import CoreLocation | |
class ViewController: UIViewController,CLLocationManagerDelegate { | |
var manager:CLLocationManager = CLLocationManager() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
manager.delegate = self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LocationManager.shared.observeLocations(.Block, frequency: .OneShot, onSuccess: { location in | |
// Your desidered CLLocation is here, at specified accuracy with auth request managed for you | |
}) { error in | |
// Something went wrong. error will tell you what | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LocationManager.shared.locateByIPAddress(onSuccess: { placemark in | |
// placemark is a valid CLPlacemark object | |
}) { error in | |
// something wrong has occurred; error will tell you what | |
} |
OlderNewer