ios - 在 SKScene 上呈现一个 viewController

标签 ios iphone objective-c xcode sprite-kit

我试图在 SkView 上显示 UIActivityViewController 但 xcode 给我这个错误:

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? 谢谢。

最佳答案

我们可以通过使用此代码访问 Root View Controller 来使用“presentModalViewController”

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

现在可以正常使用了!

关于ios - 在 SKScene 上呈现一个 viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21089332/

相关文章:

ios - UIButton 子类突出显示错误(即使在点击或触摸后突出显示仍然存在)

ios - 声明是否确实需要Objective-C属性吗?

ios - raywenderlich 的 AFNetworking 教程不在表格单元格上显示数据

ios - Xcode 5 自动布局 - 嵌入式表格

ios - NSMutableData 到 NSDictionary 返回 null

objective-c - 注册应用程序的 SoundCloud API 和 401 错误

ios - 使用 SQLITE 的 Swift 应用程序在更新数据库后崩溃。 SQLITE 文件未复制到文件/包

iphone - 为什么此代码无法使用 MPMoviePlayerController 播放歌曲

c# - Xamarin iOS C# 从 UIWebView 在 Safari 中打开链接

iphone - 点击手势 + 长按手势都不能一起工作