iphone:uiscrollview不滚动?但内容设置..?

时间:2011-05-22 16:01:00

标签: iphone uiscrollview scroll

嘿,人们, 我有一些数据,并希望在导航堆栈中的新视图中显示它。

我用XIB文件创建了一些新的viewcontroller类。然后我编辑了XIB文件并放置了下面的层次结构:

1 files owner
2 first responder
3 scrollview
3.1 view
3.1.1 label1
3.1.2 label2
3.1.3 label3
3.1.4 image4

我安排了标签和图片。标签的内容可能不同,它们应该动态调整大小。我还在viewcontroller类中完成了IBOutlets并正确连接了所有内容。文件所有者的视图委托设置为查看..

然后我加载了viewcontroller,我在“viewDidLoad”中执行了以下方法:

- (void)viewDidLoad {
[super viewDidLoad];

self.currentPageURL.text = [self.offerItem objectForKey: @"page-url"];
self.currentPrice.text = [self.offerItem objectForKey: @"price"];
self.currentRank.text = [self.offerItem objectForKey: @"rank"];
self.currentName.text = [self.offerItem objectForKey: @"name"];
self.currentProducerName.text = [self.offerItem objectForKey: @"producer-name"];

self.currentDescription.text = [self.offerItem objectForKey: @"description"];

self.imageViewForImage.image = [helperClass resizeImage:[self.offerItem objectForKey: @"picture"] forSize:CGSizeMake(280.0, 280.0) ];

[theScrollview setScrollEnabled:YES];
[theScrollview setContentSize:CGSizeMake(320, 1200)];
[theScrollview flashScrollIndicators];

[theScrollview addSubview:theView];

}

当我在我的模拟器中启动应用程序时,会显示所有内容,但如果我尝试滚动,则没有任何反应..

我做错了什么?

3 个答案:

答案 0 :(得分:19)

Autolayout在视图加载后设置了一些约束,因此,选择在viewDidLoad中设置内容大小并放入viewDidAppear的代码,并且不会重写代码。

这对我有用。

-(void)viewDidAppear:(BOOL)animated{
  [self.scrollView setContentSize:CGSizeMake(320, 1000)];
}

抱歉我的英语不好。

答案 1 :(得分:10)

确保IB Document属性中的“使用Autolayout”未选中。我有完全相同的问题,设置正确的contentSize和所有,但启用此功能后,始终禁用滚动。

Use Autolayout needs to be OFF

UPDATE 要使用Autolayout,请在viewDidAppear方法中显式设置scrollView内容的宽度和高度,如下所示:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // set the scrollview to the specified size
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    [scrollView setContentSize:CGSizeMake(screenRect.size.width, 1100)];

    [scrollView setBounds:CGRectMake(0, 0, screenRect.size.width, screenRect.size.height)];

    [scrollView setScrollIndicatorInsets:UIEdgeInsetsFromString(@"{0,0,0,-1.0}")];

}

答案 2 :(得分:4)

立即将theScrollView的框架更改为320x480,您应该看到滚动。

相关问题