Converting a CGPoint to NSValue

后端 未结 7 1896
猫巷女王i
猫巷女王i 2020-12-17 09:42

In CABasicAnimation.fromValue I want to convert a CGPoint to a \"class\" so I used NSValue valueWithPoint but in device m

7条回答
  •  一整个雨季
    2020-12-17 10:38

    If you are using a recent-ish version of Xcode (post 2015), you can adopt the modern Objective-C syntax for this. You just need to wrap your CGPoint in @():

    CGPoint primitivePoint = CGPointMake(4, 6);
    NSValue *wrappedPoint = @(primitivePoint);
    

    Under the hood the compiler will call +[NSValue valueWithCGPoint:] for you.

    https://developer.apple.com/library/archive/releasenotes/ObjectiveC/ModernizationObjC/AdoptingModernObjective-C/AdoptingModernObjective-C.html

提交回复
热议问题