我正在使用以下方法来访问有关对象的数据。第一个 NSLog 显示所有数据。第二个 NSLog 显示“帧”数据,结果如下: NSRect: {{168, 102}, {5, 5}}
如何从 NSRect 访问第一组坐标,然后从第一对访问横坐标?
-(void) moveTheShape:(NSTimer*)timer
{
NSDictionary *userInfo = [timer userInfo];
NSLog(@"Info: %@",userInfo);
//Info: <Shape: 0x68b6c30; frame = (151 352; 5 5); layer = <CALayer: 0x68b6c00>>
NSDictionary *frame = [userInfo valueForKey:@"frame"];
NSLog(@"frame: %@", frame);
//NSRect: {{168, 102}, {5, 5}}
}
正确的解决方案:
-(void) moveTheShape:(NSTimer*)timer
{
Shape *userInfo = [timer userInfo];
NSLog(@"Info: %@",userInfo);
CGPoint origin = userInfo.frame.origin;
NSLog(@"result: %f", origin.x);
}