Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get this value as a CGFloat?

Tags:

casting

iphone

I am asking for an Value like this:

[self.layer valueForKeyPath:@"transform.rotation.z"]

bit I need to pass it to a method which takes a CGFloat as parameter. What's the casting trick here?

like image 754
Thanks Avatar asked Jul 31 '09 14:07

Thanks


People also ask

What does CGFloat mean?

A CGFloat is a specialized form of Float that holds either 32-bits of data or 64-bits of data depending on the platform. The CG tells you it's part of Core Graphics, and it's found throughout UIKit, Core Graphics, Sprite Kit and many other iOS libraries.

Is CGFloat a double?

As others have said, CGFloat is a float on 32-bit systems and a double on 64-bit systems.

What is CGFloat in Objective C?

In Objective-C, we generally use CGFloat for doing floating point operation, which is derived from basic type of float in case of 32-bit and double in case of 64-bit.


1 Answers

In Swift:

let f = view.layer.valueForKeyPath("transform.rotation.z")!.floatValue

In Objective-C:

NSNumber* n = [self.layer valueForKeyPath:@"transform.rotation.z"];
CGFloat f = [n floatValue];
like image 53
Rhythmic Fistman Avatar answered Sep 28 '22 08:09

Rhythmic Fistman