这是我尝试配置的.m的一部分: 这是我的UIAlertView:
NSString *message = [NSString stringWithFormat:@"Score %d", _score];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Game Over"
message:message
delegate:nil
cancelButtonTitle:@"Play Again"
otherButtonTitles:nil];
[av show];
我正在尝试制作上面的UIAlertView,所以当我点击Play Again时,它会这样做:
[self runAction:[SKAction sequence:@[[SKAction repeatAction:[SKAction sequence:@[[SKAction runBlock:^{
}], [SKAction waitForDuration:0.05], [SKAction waitForDuration:0.05]]] count:4], [SKAction runBlock:^{
_canRestart = YES;
}]]]];
这是我的.h:
#import <SpriteKit/SpriteKit.h>
@interface MyScene : SKScene
@end
我已经添加了vborra所说的内容,我仍然使用未声明的标识符'alertView'消息。在.h中声明,这是我正在尝试配置的.m中的代码
(void)alertView:UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex [self runAction:[SKAction序列:@ [[SKAction repeatAction:[SKAction sequence:@ [[SKAction runBlock:^ {
}], [SKAction waitForDuration:0.05], [SKAction waitForDuration:0.05]]] count:4], [SKAction runBlock:^{
_canRestart = YES;
}]]]];
答案 0 :(得分:0)
查看UIAlertViewDelegate
,每当按下提醒时都会调用它:https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Game Over" message:message delegate:self cancelButtonTitle:@"Play Again" otherButtonTitles:nil];
然后在你的委托方法(- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
)中:
[self runAction:[SKAction sequence:@[[SKAction repeatAction:[SKAction sequence:@[[SKAction runBlock:^{
}], [SKAction waitForDuration:0.05], [SKAction waitForDuration:0.05]]] count:4], [SKAction runBlock:^{
_canRestart = YES;
}]]]];
然后按下“确定”按钮后游戏将重新启动。