开发者

iOS super weird problem, subviews added without me adding them

开发者 https://www.devze.com 2023-03-15 08:46 出处:网络
I have a UIScrollView which I add a couple of subviews to (done in loadView) (see code): // Add the views to the Scroll View

I have a UIScrollView which I add a couple of subviews to (done in loadView) (see code):

// Add the views to the Scroll View
[scrollView addSubview:label];
[scrollView addSubview:careerDescriptionWebView];

self.view = scrollView;

I then later on want to calculate the height of the added subviews (done in viewWillAppear: to set the height of the UIScrollView (see this code):

// Change the height of the Scroll View dynamically to match the content
float hgt = 0开发者_JAVA技巧; 

for (UIView *view in scrollView.subviews) {
    hgt += view.frame.size.height;
    NSLog(@"View: %@, height: %f", [[view class] description], view.frame.size.height);
}    

[scrollView setContentSize:CGSizeMake(scrollView.frame.size.width,hgt)];

So later when I check the output of the console I see this:

2011-06-23 13:34:48.344 Acando[90355:207] View: UILabel, height: 21.000000
2011-06-23 13:34:48.345 Acando[90355:207] View: UIWebView, height: 1017.000000
2011-06-23 13:34:48.346 Acando[90355:207] View: UIImageView, height: 7.000000
2011-06-23 13:34:48.347 Acando[90355:207] View: UIImageView, height: 145.000000

This doesn't appear immediately, at first it appears correctly with only a UILabel and a UIWebView it seems to appear randomly after loading the viewcontroller a couple of times.


This because scrollview have 2 more things in this view, one is the horizonal scroller and the second is the vertical scroller which will be shown automatically when you scroll up and down and right and left

0

精彩评论

暂无评论...
验证码 换一张
取 消