Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 取消在场景中以编程方式添加为子视图的textview_Ios_Objective C_Sprite Kit_Uitextview_Skscene - Fatal编程技术网

Ios 取消在场景中以编程方式添加为子视图的textview

Ios 取消在场景中以编程方式添加为子视图的textview,ios,objective-c,sprite-kit,uitextview,skscene,Ios,Objective C,Sprite Kit,Uitextview,Skscene,正如标题所示,我在场景中添加了一个UITextView,效果很好。我唯一的问题是,当我使用后退按钮返回主菜单时,文本视图仍保留在屏幕上。就我的一生而言,如果按下“后退”按钮,我不知道如何防止此文本视图保留在屏幕上。谁能帮帮我吗。以下是我在场景中使用的代码: @implementation HowToPlay -(void)didMoveToView:(SKView *)view { SKSpriteNode *bgImage = [SKSpriteNode spriteNodeWithIm

正如标题所示,我在场景中添加了一个UITextView,效果很好。我唯一的问题是,当我使用后退按钮返回主菜单时,文本视图仍保留在屏幕上。就我的一生而言,如果按下“后退”按钮,我不知道如何防止此文本视图保留在屏幕上。谁能帮帮我吗。以下是我在场景中使用的代码:

@implementation HowToPlay


-(void)didMoveToView:(SKView *)view {

SKSpriteNode *bgImage = [SKSpriteNode spriteNodeWithImageNamed:@"vortex1.jpg"];
bgImage.size = self.frame.size;
bgImage.position = CGPointMake(self.size.width/2, self.size.height/2);
[self addChild:bgImage];

SKLabelNode *myLabel = [SKLabelNode labelNodeWithFontNamed:@"Thonburi-Bold"];
myLabel.text = @"Title";
myLabel.fontSize = 20;
myLabel.fontColor = [UIColor whiteColor];
myLabel.position = CGPointMake(275,290);
[self addChild:myLabel];

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(150, 40, 300, 240)];
textView.backgroundColor = [ UIColor  clearColor];
textView.text = @"this is the body of the text that we are going to use and add the story line to it.this is the body of the text that we are going to use and add the story line to it.\n\nthis is the body of the text that we are going to use and add the story line to it.this is the body of the text that we are going to use and add the story line to it.this is the body of the text that we are going to use and add the story line to it.\n\nthis is the body of the text that we are going to use and add the story line to it.this is the body of the text that we are going to use and add the story line to it.";
textView.font = [UIFont fontWithName:@"Helvetica" size:20];
textView.textColor = [UIColor whiteColor];
[self.view addSubview:textView];

[self addChild: [self backButton]];
}
- (SKSpriteNode *)backButton
{
SKSpriteNode *button = [SKSpriteNode spriteNodeWithImageNamed:@"Back.png"];
[button setScale:0.5];
button.position = CGPointMake(50, 50);
button.name = @"Back";
return button;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];

if ([node.name isEqualToString:@"Back"]) {
    [self runButtonActionOnNodeBack:node];
}
}

-(void)runButtonActionOnNodeBack:(SKNode*) node{
node.name = nil;
//SKAction *moveUp = [SKAction moveByX: 0 y: 100.0 duration: 0.5];
SKAction *zoom = [SKAction scaleTo: 0.8 duration: 0.25];
// *spin = [SKAction rotateToAngle:360.0f duration:1.0];
SKAction *pause = [SKAction waitForDuration: 0.5];
SKAction *fadeAway = [SKAction fadeOutWithDuration: 0.25];
SKAction *remove = [SKAction removeFromParent];
SKAction *moveSequence = [SKAction sequence:@[zoom, pause, fadeAway, remove]];
[node runAction: moveSequence completion:^{
    SKScene *mainMenu  = [[GameScene alloc] initWithSize:self.size];
    SKTransition *doors = [SKTransition doorsOpenHorizontalWithDuration:0.5];
    [self.view presentScene:mainMenu transition:doors];
}];
}
@end

保存对该文本视图的引用,然后在要删除该文本视图时将其从其superview中删除:

@interface HowToPlay()
@property (nonatomic, strong) UITextView *textView;
@end

@implementation HowToPlay

- (void)didMoveToView:(SKView *)view {
    self.textView = [[UITextView alloc]......
}

//whenever you want to open the menu/remove the text view:
[self.textView removeFromSuperview];

干得好。谢谢。我真不敢相信我竟然不明白。我猜我花了太多时间设计游戏,而我完全忘记了uikit。再一次感谢一百万的答案,还有+1兄弟。当你发现自己在搜索某个问题,并且意识到你已经在某个时候对该问题的答案投了赞成票时,这才是令人尴尬的。。。(:我这么做了吗?我不认为我这么做了,但不管怎样,这还是很尴尬的。现在为什么有人会对这个问题投反对票而不评论为什么?这是不道德的。我不介意投反对票,我只是想知道为什么。