在SKScene上呈现一个viewController [英] Presenting a viewController on SKScene

查看:258
本文介绍了在SKScene上呈现一个viewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 SkView 上展示 UIActivityViewController ,但是xcode给了我这个错误:

I am trying to present UIActivityViewController on an SkView but xcode gives me this error :


'GameOver'没有可见的@interface声明选择器
'resentViewController:animated:completion:'

No visible @interface for 'GameOver' declares the selector 'presentViewController:animated:completion:'



- (void)shareScore {

    //add view
    UIView *Sview  = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 512, 512)];
    UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"shareScoreImg.png"]];
    image.frame = Sview.frame;
    [Sview addSubview:image];

    //add label
    CGRect fframe = self.view.frame;

    UILabel *score = [[UILabel alloc] initWithFrame:fframe];
    score.text = @"9999";
    score.textAlignment = NSTextAlignmentCenter;
    score.textColor = [UIColor darkGrayColor];
    score.center = CGPointMake(250, 440);
    score.font = [UIFont fontWithName:@"Pixel LCD7" size:50];
    [Sview addSubview:score];


    //capture view
    UIGraphicsBeginImageContextWithOptions(Sview.bounds.size, Sview.opaque, 0.0);
    [Sview.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    UIActivityViewController* activityViewController =
    [[UIActivityViewController alloc] initWithActivityItems:@[screenshot]
                                      applicationActivities:nil];

    [self presentViewController:activityViewController animated:YES completion:nil];

}

如何在SKScene上呈现预设的viewController?
谢谢。

How can I present preset a viewController on SKScene ? thanks .

推荐答案

我们可以使用presentModalViewController通过使用此代码访问根视图控制器

We can use "presentModalViewController" by using this code to access the root view controller

 UIViewController *vc = self.view.window.rootViewController;
    [vc presentViewController: activityViewController animated: YES completion:nil];

现在工作正常!

这篇关于在SKScene上呈现一个viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆