Scroll View not functioning IOS 7

前端 未结 2 732
慢半拍i
慢半拍i 2020-12-02 07:13

I have a scrollview inside which i have 20 UItextviews. The scrollview is not working. I have set the following in viewdidload.

self.MainScroll.contentSize =          


        
相关标签:
2条回答
  • 2020-12-02 07:26

    There are two ways you can get the scrolling to work.

    Approach 1 (with code):

    1) Pin UIScrollView to the sides of its parent view, as mentioned below.

    enter image description here

    2) Set content size of your scroll view in viewDidLayoutSubviews:

    - (void)viewDidLayoutSubviews {
        self.MainScroll.contentSize = CGSizeMake(320, 1800);
    }
    

    Approach 2 (pure IB, no code required):

    1) Setting contentSize is not required if using AutoLayout. You need to pin your UIScrollView to the parent view as mentioned below:

    enter image description here

    2) Then add another UIView inside UIScrollView to act as a content view and pin it to the UIScrollView and move all controls inside this content view:

    enter image description here

    3) Pin content view to its parent scroll view as mentioned below:

    enter image description here

    4) Set your UIViewController's Simulated Metrics to Freeform (this is important):

    enter image description here

    5) Size your content UIView to your desired height (obviously important too):

    enter image description here

    Apple article explaining UIScrollView and AutoLayouts: https://developer.apple.com/library/content/technotes/tn2154/_index.html

    0 讨论(0)
  • 2020-12-02 07:31

    Update the content size after some delay as below.

    - (void)viewDidLayoutSubviews {
        [self performSelector:@selector(updateContentSize)
                   withObject:nil
                   afterDelay:0.25];
    
    }
    
    -(void)updateContentSize{
        UIView *viewLast = [viewContent viewWithTag:100];
        scrollViewAd.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, CGRectGetMaxY(viewLast.frame));
    }
    
    0 讨论(0)
提交回复
热议问题