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 //:)
6 answers
Właściwie, najprostszym sposobem na zalogowanie się CGPoint
jest:
NSLog(@"%@", NSStringFromCGPoint(point));
Odpowiednikiem kakao na pulpicie jest NSStringFromPoint()
.
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);
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
.
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);
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]);
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
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