简体   繁体   English

使滚动适合整个屏幕?

[英]Fit the scrolling to the entire screen?

Hi I just added the functionality of endless vertical scrolling to my app but I can't figure out how to make size it to the size of the screen. 嗨,我刚刚在我的应用程序中添加了无限垂直滚动功能,但是我不知道如何将其调整为屏幕尺寸。 A photo is attached of what i mean. 附上我的意思的照片。 Any help would be appreciated! 任何帮助,将不胜感激!

忽略星巴克徽标和矩形大声笑只是占位符

Here is my code 这是我的代码

@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];

    }
}

What you need to do here is set the content view height according to number of content you need to display in scroll view. 您需要在此处根据要在滚动视图中显示的内容数来设置内容视图的高度。

eg : if you nee 5 view to display in scroll view then you need to set content size of scroll view to 5*viewHeight*yPos of last object. 例如:如果要在滚动视图中显示5个视图,则需要将滚动视图的内容大小设置为最后一个对象的5 * viewHeight * yPos。

But the frame of scroll should be — {{0,0},{self.view.frame.size.width,self.view.frame.size.height}} and content size can be {320,1000} or {320,500} where height and width of content size can be greater than frame of scroll view. 但是滚动帧应为-{{0,0},{self.view.frame.size.width,self.view.frame.size.height}},内容大小可以为{320,1000}或{320,500 },其中内容大小的高度和宽度可以大于滚动视图的框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM