1

我想将 CGpoint 发送到我的主控制器类。所以我使用通知发送cgpoint,但我不知道如何从接收方的通知中提取cgpoint。我的日志输出只得到 0.00。

这是我的代码。

AT发件人:

 NSValue *pointAsObject =[NSValue valueWithCGPoint:CGPointMake(touchDetectingView.lastTouchPosition.x, touchDetectingView.lastTouchPosition.y)];
  [[NSNotificationCenter defaultCenter] postNotificationName: @"swap" object:pointAsObject];

AT接收头文件:

- (void)incomingNotification:(NSNotification *)notification;

在接收器 M 文件

[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(incomingNotification:) name:@"swap" object:nil];

- (void)incomingNotification:(NSNotification *)notification
{
     NSValue *pointAsObject = [[notification userInfo] valueForKey:@"swap"];
    NSLog (@"Successfully received the test notification %f",pointAsObject.CGPointValue.y);
}

但我只得到 0.00 OUTPUT ..

4

1 回答 1

3
- (void)incomingNotification:(NSNotification *)notification
{
     NSValue *pointAsObject = [notification object];
    NSLog (@"Successfully received the test notification %f",pointAsObject.CGPointValue.y);
}
于 2013-04-05T13:36:34.090 回答