ios – 在SKScene上呈现viewController
发布时间:2020-12-15 01:44:19 所属栏目:百科 来源:网络整理
导读:我试图在SkView上呈现UIActivityViewController,但xcode给了我这个错误: No visible @interface for ‘GameOver’ declares the selector ‘presentViewController:animated:completion:’ - (void)shareScore { //add view UIView *Sview = [[UIView alloc
我试图在SkView上呈现UIActivityViewController,但xcode给了我这个错误:
- (void)shareScore { //add view UIView *Sview = [[UIView alloc]initWithFrame:CGRectMake(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]; 现在它工作正常! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |