3

Why can't I see the text in the SKScene? Is this the right way to have UIScrollView in SKScene?

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

        UIScrollView * contentScrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
        contentScrollView.backgroundColor = [UIColor whiteColor];
        [contentScrollView setUserInteractionEnabled:YES];

        UITextView * mainContent = [[UITextView alloc]initWithFrame:self.view.frame];
        mainContent.text = @"HELLO WORLD";
        mainContent.textColor = [UIColor blackColor];

        [contentScrollView addSubview:mainContent];
        [self.view addSubview:contentScrollView];

    }
    return self;
}
malat
  • 12,152
  • 13
  • 89
  • 158
user1614097
  • 75
  • 1
  • 3
  • Take a look at this answer for further information: http://stackoverflow.com/a/20800868/867635 –  Apr 05 '14 at 15:15

2 Answers2

5

At this point (when initializing your scene with -(id)initWithSize:(CGSize)) there is no view associated with your scene. If you want to add UIScrollView to your scene you should do it inside -(void)didMoveToView:(SKView*) method.

Also if you want your UIScrollView to contain SKNodes you might have a look at https://stackoverflow.com/a/19096256/2328918

EDIT 2014-04-20

I have open sourced my component for panning and scrolling scenes in SpriteKit, please have a look at: https://github.com/pzbyszynski/PIOSpriteKit

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
0

ScrollKit can do spritekit in a scrollview.

neoneye
  • 50,398
  • 25
  • 166
  • 151