滚动适合整个屏幕?

时间:2015-03-13 02:56:50

标签: ios objective-c sprite-kit infinite-scroll

您好我刚刚向我的应用添加了无尽垂直滚动的功能,但我无法弄清楚如何根据屏幕大小调整大小。照片附有我的意思。任何帮助将不胜感激!

ignore the starbucks logo and rectangle lol just placeholders

这是我的代码

@implementation GameScene
{
    SKNode* _bglayer;
    SKNode* _gamelayer;
    SKNode* _HUDlayer;
    NSTimeInterval* _dt;
    NSTimeInterval* _lastUpdateTime;


}

-(void)didMoveToView:(SKView *)view {
    /* Setup your scene here */
    [self addChild:[self createCharacter] ];
    [self performSelector:@selector(createTile) withObject:nil afterDelay:2.0];

    _bglayer =[SKNode node];
    [self addChild:_bglayer];
    _gamelayer =[SKNode node];
    [self addChild:_gamelayer];
    _HUDlayer =[SKNode node];
    [self addChild:_HUDlayer];

    SKTexture* backgroundTexture=[SKTexture textureWithImageNamed:@"wallpaper1"];


    SKAction* moveBg =[SKAction moveByX:0 y:-backgroundTexture.size.height*2 duration:0.01*backgroundTexture.size.height];

    SKAction *resetBg =[SKAction moveByX:0 y:backgroundTexture.size.height*2 duration:0];
    SKAction *moveBackgroundForever =[SKAction repeatActionForever:[SKAction sequence:@[moveBg,resetBg]]];

    for (int i=0; i<2 +self.frame.size.height/(backgroundTexture.size.height*2);++i){
        SKSpriteNode* sprite = [SKSpriteNode spriteNodeWithTexture:backgroundTexture];

        [sprite setScale:1.0];
        sprite.zPosition=-100;
        sprite.anchorPoint=CGPointZero;
        sprite.position=CGPointMake(350, i*sprite.size.height);
        [sprite runAction:moveBackgroundForever];
        [_bglayer addChild:sprite];

    }
}

1 个答案:

答案 0 :(得分:0)

您需要在此处执行的操作是根据您需要在滚动视图中显示的内容数量来设置内容视图高度。

e.g。 :如果您需要在滚动视图中显示5视图,则需要将滚动视图的内容大小设置为最后一个对象的5 * viewHeight * yPos。

但滚动框架应该是 - {{0,0},{self.view.frame.size.width,self.view.frame.size.height}},内容大小可以是{320,1000}或{320,500}其中内容大小的高度和宽度可以大于滚动视图的帧。