2

我是 iOS 新手,遇到UIScrollView. 卷轴在此不起作用,请您帮帮我:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 310,300, 999)];

label.text = self.selString;
label.numberOfLines = 0;
// [self.view addSubview:label];

UIImageView *image = 
  [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 300, 300)];
image.backgroundColor = [UIColor greenColor];
image.tag = 50;
image.userInteractionEnabled=YES;
image.autoresizesSubviews = YES;
image.alpha = 0.93;
image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://opensum.in/app_test_f1/45djx96.jpg"]]];   // working code
//[self.view addSubview:image];

self.title = @"Full Blog";

CGRect scrollViewFrame = CGRectMake(0,0, 320, 999);
scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
scrollView.pagingEnabled =YES;
[self.view  addSubview:scrollView];

scrollView.tag=1000;


[scrollView addSubview:label];
[scrollView addSubview:image];
4

4 回答 4

4

设置UIScrollView contentSize

CGSize contentSize = CGSizeMake([[UIScreen mainScreen]bounds].size.width, 1000);
[scrollView setContentSize:contentSize];
于 2015-09-01T07:27:53.890 回答
1

试试这个代码:

UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 310,300, 999)];

label.text=self.selString;
label.numberOfLines=0;

UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 300, 300)];
image.backgroundColor = [UIColor greenColor];
image.tag = 50;
image.alpha = 0.93;
image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://opensum.in/app_test_f1/45djx96.jpg"]]];

CGRect scrollViewFrame = CGRectMake(0,0, 320, 999);
scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
scrollView.tag=1000;

[scrollView addSubview:image];
[scrollView addSubview:label];
[self.view  addSubview:scrollView];

scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 999);// your scroll scroll height give here
于 2015-09-01T07:29:23.350 回答
1

像这样设置滚动视图的内容高度

[scrollView setContentSize:(CGSizeMake(320, 999))];
于 2015-09-01T07:41:50.173 回答
1

你需要设置contentSize你的UIScrollView. 如果没有设置,它将不会显示滚动。而且您的 contentSize 应该比您的scrollView.frame.size.

现在,你scrollView有一个巨大的 frame.height。使用较小的值。并为 contentSize.height 使用更高的值。

于 2015-09-01T07:28:01.497 回答