Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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
Objective c 当UIScrollView充满更多内容时扩展它_Objective C - Fatal编程技术网

Objective c 当UIScrollView充满更多内容时扩展它

Objective c 当UIScrollView充满更多内容时扩展它,objective-c,Objective C,好的,当用户登录到我的应用程序时,我得到了一个要加载的scrollview。当用户通过身份验证时,我需要以编程方式创建一个scrollview。为此,我有以下代码: [scrollView removeFromSuperview]; UIScrollView *view = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, applicationFrame.size.width, self.view.frame.size.

好的,当用户登录到我的应用程序时,我得到了一个要加载的scrollview。当用户通过身份验证时,我需要以编程方式创建一个scrollview。为此,我有以下代码:

[scrollView removeFromSuperview];

        UIScrollView *view = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, applicationFrame.size.width, self.view.frame.size.height)];
        view.backgroundColor = [UIColor greenColor];


        //-- get the y-coordinate of the view
        CGFloat viewCenterY = self.view.center.y;
        //--calculate how much visible space is left
        CGFloat freeSpaceHeight = applicationFrame.size.height - keyboardBounds.size.height;
        //-- calculate how much the scrollview must scroll
        CGFloat scrollAmount = viewCenterY - freeSpaceHeight / 2.0;

        if(scrollAmount < 0) scrollAmount = 0;

        //set the new scrollsize contentview
        view.contentSize = CGSizeMake(applicationFrame.size.width,         applicationFrame.size.height + keyboardBounds.size.height);

        //scroll the scrollview
        [view setContentOffset:CGPointMake(0, scrollAmount) animated:YES];

            for(int v = 0; v < 15; v++){
                CGFloat yCoord = v * 100;
                UILabel *mijnLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, yCoord, 200, 50)];

                mijnLabel.text = @"1337";
                mijnLabel.font = [UIFont fontWithName:@"Verdana" size:20];
                mijnLabel.textColor = [UIColor redColor];

                [view addSubview:mijnLabel];
                [mijnLabel release];
            }


            [self.view addSubview:view];

            [view release];


        }

您需要跟踪添加到滚动视图中的标签编号。假设标签的高度为50,则取一个变量,合计所有标签的高度,并为滚动视图提供一个新的帧。比如:

        view.frame = CGRectmake(0,0,applicationFrame.size.width,totalHeightOfLabel);
        [self.view addSubview:view];

        [view release];
希望这能给你一个想法

        view.frame = CGRectmake(0,0,applicationFrame.size.width,totalHeightOfLabel);
        [self.view addSubview:view];

        [view release];