簡體   English   中英

在SKScene上呈現一個viewController

[英]Presenting a viewController on SKScene

我試圖在SkView上呈現UIActivityViewController ,但xcode給了我這個錯誤:

'GameOver'沒有可見的@interface聲明選擇器'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? 謝謝 。

我們可以使用“presentModalViewController”來使用此代碼來訪問根視圖控制器

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

現在它工作正常!

IIRC您創建的第一個SKScene是在SKView內部。

這個SKView位於UIViewController

您可以使用屬性或委托或任何您喜歡的方法通過SKViewSKScene訪問UIViewController上的方法。 甚至使用通知。

然后在UIViewController上,您可以UIViewController地呈現新的視圖控制器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM