Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在方向改变时暂停游戏,objective-c/精灵套件_Objective C_Sprite Kit - Fatal编程技术网

在方向改变时暂停游戏,objective-c/精灵套件

在方向改变时暂停游戏,objective-c/精灵套件,objective-c,sprite-kit,Objective C,Sprite Kit,我想在设备定向启动时暂停游戏。我的viewcontroller中有此方法,效果很好: - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { NSLog(@"I am starting to rotate, should pause game.."); } 但是如何从我的场景中听到设备的旋转,在那里实际的

我想在设备定向启动时暂停游戏。我的viewcontroller中有此方法,效果很好:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
NSLog(@"I am starting to rotate, should pause game..");
}


但是如何从我的场景中听到设备的旋转,在那里实际的游戏正在进行。希望我已经讲清楚了。谢谢你的帮助

您可以使用
NSNotification
。按照代码,在ViewController init中添加以下行:

[[NSNotificationCenter defaultCenter] 
    postNotificationName:@"RotateNotification" 
                  object:self];
然后在SKScene init中添加以下行:

[[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(receiveNotification:) 
        name:@"RotateNotification"
      object:nil];
还要将调用的方法添加到场景:

-(void) receiveNotification:(NSNotification *)notification
{
    NSLog (@"Received notification");
    // do what you have to do here...
}

你试过在场景中使用相同的代码吗?是的,willRotate。。。不会因为方向改变而被解雇。。