iphone:uiscrollview 不滚动?但内容大小已设置..?
嘿人们, 我有一些数据,想在导航堆栈内的新视图中显示这些数据。
我使用 XIB 文件创建了一些新的视图控制器类。然后我编辑了 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 并正确连接了所有内容。文件所有者的视图委托设置为 view..
然后我加载视图控制器,并在“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];
}
当我在模拟器中启动应用程序时,所有内容都会显示,但如果我尝试滚动,什么也没发生..
我做错了什么?
hey people,
I have some data and want to show this in a new view inside a navigation-stack.
I created some new viewcontroller class with XIB file. Then I edited the XIB file and placed the following hierachy:
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
I arranged the labels and the image. the content of the labels may differ and they should size dynamically. I also did the IBOutlets in the viewcontroller class and connected everything correctly. the files owner's view delegate is set to view..
then I load the viewcontroller and I do in the "viewDidLoad" - method the following:
- (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];
}
when I start the app in my simulator, everything is shown, but if I try to scroll, nothing happens..
what do I do wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
自动布局在视图加载后设置了一些约束,因此,选择在 viewDidLoad 中设置内容大小的代码并将其放入 viewDidAppear 中,这样你的代码就不会被重写。
这对我有用。
抱歉我的英语不好。
Autolayout set some constraints after the view loads, so, pick your code that sets the content size in viewDidLoad and put in viewDidAppear, and your code won't be rewritten.
This worked for me.
and sorry for my poor english.
确保 IB 文档属性中的“使用自动布局”未选中。我遇到了完全相同的问题,设置了正确的 contentSize 等,但启用此功能后,滚动始终被禁用。
更新 要使用自动布局,请显式设置布局的宽度和高度viewDidAppear方法中scrollView的内容,如下所示:
Ensure that "Use Autolayout" is unchecked in the IB Document attributes. I had the exact same issue, setting the correct contentSize and all, but with this feature enabled, scrolling was always disabled.
UPDATE To use Autolayout, explicitly set the width and height of the scrollView's content in the viewDidAppear method, like this:
立即将
theScrollView
的框架更改为 320x480,您应该会看到滚动。Immediately change the frame of
theScrollView
to 320x480 and you should see scrolling.