在呈现UIActivityView或呈现第二个SKScene时,应用程序会冻结几秒钟

时间:2014-08-25 01:17:41

标签: ios objective-c animation sprite-kit uiactivityviewcontroller

当我按下播放按钮或分享按钮时,应用会冻结,但仅限第一次。

第一次运行后没有冻结。

冻结持续时间为2-4秒。

我试了一段时间才找到解决办法,但我尝试的一切都行不通。

GameViewController.m

- (void)viewDidLoad
{
 [super viewDidLoad];
 SKView * skView = (SKView *)self.view;
 SKScene * scene = [Menu sceneWithSize:skView.bounds.size];
 scene.scaleMode = SKSceneScaleModeAspectFill;
 [skView presentScene:scene];
}

- (void) openShare
{
  int highScore = [self highScoreAbruf];
  NSString *shareText= [NSString stringWithFormat:@"The HIghScore is %i", highScore];
  NSArray *itemsToShare = @[shareText];
  UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
  [self presentViewController:activityVC animated:YES completion:nil];   
}

- (int) highScoreAbruf
{
  NSUserDefaults *myHighScore = [NSUserDefaults standardUserDefaults];
  int highScore = [myHighScore integerForKey:@"Score"];
  return highScore;
}

Menu.m

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {    
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];

if ([node.name isEqualToString:@"PlayButton"])
{
    PlayButton.hidden = YES;
    PlayButtonPressed.hidden = NO;

    [self restartButtonPressed];
    //[self performSelector:@selector(restartButtonPressed) withObject:nil afterDelay:(0.5)];

}

if ([node.name isEqualToString:@"ShareButton"])
{
    ShareButton.hidden = YES;
    ShareButtonPressed.hidden = NO;

    NSTimer *buttonTimer = [NSTimer scheduledTimerWithTimeInterval:(0.5)
                                                            target:self
                                                          selector:@selector(ShareMethod)
                                                          userInfo:NULL
                                                           repeats:NO];

}
}

- (void) restartButtonPressed
{
  [self.scene.view presentScene:[GameMyScene sceneWithSize:self.size]];
}

- (void) ShareMethod
{
  GameViewController *vc = self.view.window.rootViewController;
  [vc openShare];
}

0 个答案:

没有答案