NSLog z danymi CGPoint

Mam CGPoint zwany punktem, który jest przypisany dotyk:

UITouch *touch = [touches anyObject];

CGPoint point = [touch locationInView:self];

Chcę pobrać wartość współrzędnych X do mojego dziennika konsoli:

NSLog(@"x: %s", point.x);

Kiedy używam tego, wyjście loga dla tego to:

X: (null)

Zweryfikowałem, że punkt nie jest null, gdy jest wywoływany za pomocą debuggera i zmiennej watch.

Każda pomoc doceniona,

Dzięki //:)

Author: Peter Hosey, 2009-09-25

6 answers

Właściwie, najprostszym sposobem na zalogowanie się CGPoint jest:

NSLog(@"%@", NSStringFromCGPoint(point));

Odpowiednikiem kakao na pulpicie jest NSStringFromPoint().

 243
Author: Jens Ayton,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-25 12:07:50

Pkt.x jest liczbą zmiennoprzecinkową, więc należy użyć:

NSLog(@"x: %f", point.x);
 24
Author: Philippe Leybaert,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-25 10:25:04

Najprostszym sposobem na zapisanie wartości CGPoint jest użycie klasy NSValue, ponieważ daje ona wszystkie istotne wartości sformatowane ładnie dla konsoli. Tak to się robi:

NSLog(@"myPoint = %@", [NSValue valueWithCGPoint:myPoint]);

Możesz również użyć +valueWithCGRect i +valueWithCGSize metod NSValue, gdy próbujesz zalogować, powiedzmy,frame (CGRect) lub size (CGSize) Właściwości UIView.

 9
Author: Nathan de Vries,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-25 10:35:29

NSLog(@"point x,y: %f,%f", point.x, point.y);

 1
Author: Nicki,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-12 11:19:35

point.x jest liczbą zmiennoprzecinkową więc powinieneś kodować TAK:

NSLog(@"%@",[NSString StringWithFormat:@"%f",point.x]);
 0
Author: Spynet,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-24 05:14:28

Użycie:

NSLog (@"% @ ", NSStringFromCGPoint (point));

Możesz również użyć NSString dla następujących informacji:

NSStringFromCGPoint
NSStringFromCGSize
NSStringFromCGRect
NSStringFromCGAffineTransform
NSStringFromUIEdgeInsets

 0
Author: Aks,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-05-22 21:22:25