gpt4 book ai didi

ios - 从 SKScene 呈现一个 UIViewController

转载 作者:行者123 更新时间:2023-11-29 12:38:11 25 4
gpt4 key购买 nike

我正在尝试从 SKScene 中呈现一个 UIViewController,但我不知道该怎么做。 Google 搜索提供的大部分内容是如何从 SKScene 呈现共享屏幕,但这不是我想要做的。只是一个普通的 View Controller ,它有一个按钮和一个标签(也可能是一个图像)。

这是我的 Intro.m 中的代码。这不是游戏场景,只是一个带有标题、播放按钮和删除广告按钮的介绍屏幕:

#import "MyScene.h"
#import "Intro.h"
#import "PurchasedViewController.h"

@interface PurchasedViewController ()

-(id)initWithSize:(CGSize)size {

if (self = [super initWithSize:size]) {

.....

SKSpriteNode *removeAds = [SKSpriteNode spriteNodeWithImageNamed:@"removeAds"];
removeAds.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMaxY(self.frame)/6);
removeAds.zPosition = 1;
removeAds.name = @"RemoveAds";
[self addChild:removeAds];
}

- (void)performTouches:(NSSet *)touches {

for (UITouch *touch in touches) {
CGPoint pointInSKScene = [self.view convertPoint:[touch locationInView:self.view] toScene:self];
SKNode *touchedNode = [self nodeAtPoint:pointInSKScene];

if ([touchedNode.name isEqualToString:@"RemoveAds"]) {
[self runAction:[SKAction playSoundFileNamed:@"enter.mp3" waitForCompletion:NO]];

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"PurchasedViewController"];
[self presentViewController:vc animated:YES completion:nil];
}
}
}

Xcode 给我的错误是“没有可见的@interface for Intro declares 'presentViewController: animated: completion'。

我有点难过,因为我之前没有尝试从 SKScene 中呈现 UIViewController 并且在网络上找不到解决方案。

最佳答案

我找到了一个比大多数解决方案都简单得多的解决方案:

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"PurchasedVC"];
//Call on the RootViewController to present the New View Controller
[self.view.window.rootViewController presentViewController:vc animated:YES completion:nil];

如果您在 Storyboard 中创建一个 segue 并给它一个标识符,我还想出了一个更简单的方法:

[self.view.window.rootViewController performSegueWithIdentifier:@"PurchasedViewController" sender:self];

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com