[英]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
。
您可以使用屬性或委托或任何您喜歡的方法通過SKView
的SKScene
訪問UIViewController
上的方法。 甚至使用通知。
然后在UIViewController
上,您可以UIViewController
地呈現新的視圖控制器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.