2009-07-31 17 views
5

Chiedo un valore come questo:Come ottenere questo valore come CGFloat?

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

po 'ho bisogno di passare ad un metodo che prende un CGFloat come parametro. Qual è il trucco del casting qui?

risposta

19

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]; 
0

Se si voleva una, in un modo più conciso linea per farlo, si può fare:

CGFloat f = [[self.layer valueForKeyPath:@"transform.rotation.z"] floatValue]; 
Problemi correlati