Search code examples
iosswiftcore-animationunsafemutablepointer

How to use "getControlPoint(at idx: Int, values ptr: UnsafeMutablePointer<Float>!)" CAMediaTimingFunction


I user this function in OC with this

CAMediaTimingFunction *function = [CAMediaTimingFunction functionWithName:
                                   kCAMediaTimingFunctionDefault];
//get control points
CGPoint controlPoint1, controlPoint2;
[function getControlPointAtIndex:1 values:(float *)&controlPoint1];
[function getControlPointAtIndex:2 values:(float *)&controlPoint2];

NSLog(@"%@, %@", NSStringFromCGPoint(controlPoint1), NSStringFromCGPoint(controlPoint2));
//{5.2386907149499368e-11, 7.9050503334599447e-323}, {0.0078125018189894035, 4.9406564584124654e-324}

but how to convert it to swift3.1, I do this, but something wrong!

let timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)

var point1 = Float(0.0), point2 = Float(0.0)

timingFunction.getControlPoint(at: 1, values: &point1)
timingFunction.getControlPoint(at: 2, values: &point2)
print("\(String(describing: point1)),\(String(describing: point2))")
// 0.25,0.25

how to fix it? I need some help, please. take care about code print.


Solution

  •     let timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
    
        var point1: [Float] = [0.0,0.0]
        var point2: [Float] = [0.0,0.0]
    
        timingFunction.getControlPoint(at: 1, values: &point1)
        timingFunction.getControlPoint(at: 2, values: &point2)
    
        print("\(String(describing: point1)),\(String(describing: point2))")
    

    this is correct convert。