【发布时间】:2015-05-06 20:15:06
【问题描述】:
正如标题所示,我在场景中添加了一个 UITextView,它工作正常。我唯一的问题是当我使用后退按钮返回主菜单时,文本视图仍保留在屏幕上。对于我的一生,如果按下后退按钮,我无法弄清楚如何防止此文本视图保留在屏幕上。有人可以帮帮我吗?以下是我在 SKScene 中使用的代码:
@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
【问题讨论】:
-
现在为什么有人反对这个问题而不评论为什么?这是不道德的。我不介意不投票,我只是想知道为什么。
标签: ios objective-c sprite-kit uitextview skscene