Giter Club home page Giter Club logo

Comments (12)

lluisgerard avatar lluisgerard commented on July 22, 2024

Note: I can set the contentSize to what I know this UIScrollView height will be BUT what's the point of using autolayout then?

from masonry.

cloudkite avatar cloudkite commented on July 22, 2024

UIScrollView and AutoLayout are sadly not the best of friends. I haven't run into this problem alot as most of the time I use UICollectionView for scrolling content.

However I have been meaning to add a UIScrollView example to the example app. I'll add something after work today which will hopefully help you with your issue :)

from masonry.

TheCoordinator avatar TheCoordinator commented on July 22, 2024

We had exactly the same issue as well. Took us about a few days to figure out exactly what's going on. My colleague @bizz84 has posted a good example here https://github.com/bizz84/MVScrollViewAutoLayout on how to use UIScrollView and Masonry together.

Please let me know if you find any issues on understanding the code.

from masonry.

lluisgerard avatar lluisgerard commented on July 22, 2024

@cloudkite Thanks for your reply! will check @bizz84 code and see how others solved the problem.
@PeymanKh Thanks, will download it right now :) 👍

from masonry.

lluisgerard avatar lluisgerard commented on July 22, 2024

Ok guys, just read the AutoLayoutViewController.m in the example that @PeymanKh referred here and I got it!

SOLUTION
The problem is that you need a bottom/footer view for AutoLayout to know the contentSize of the entire content.

If you add this code to the code I posted here in my first question you will have a nice scrolling ScrollView 👍

    // NECESSARY TO SCROLL!
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectZero];
    bottomView.backgroundColor = [UIColor redColor];
    [_scrollView addSubview:bottomView];
    // last one, pin to bottom and right, this dictates content size height
    [bottomView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view3.bottom).offset(10);
        make.left.equalTo(_scrollView.left).offset(10);
        make.width.equalTo(_scrollView.width).offset(-20);
        make.height.equalTo(@50);
        make.bottom.equalTo(_scrollView.bottom).offset(-10);
    }];

Again, @cloudkite and everybody that contributes to this awesome project, thank you! really appreciate the time it saves me to use this framework.

from masonry.

TheCoordinator avatar TheCoordinator commented on July 22, 2024

Glad I could help.

from masonry.

cloudkite avatar cloudkite commented on July 22, 2024

@PeymanKh thanks for helping out!

I have added a UIScrollView example to the example app now, hopefully will help other people who come across this issue.

from masonry.

lluisgerard avatar lluisgerard commented on July 22, 2024

Just a note here about Autolayout and UIScrollViews, scrollRectToVisible is not working for me anymore:

   [self.scrollView scrollRectToVisible:textField.frame animated:YES];

And had to use setContentOffset instead:

   [self.scrollView setContentOffset:contentOffset animated:YES];

I wonder why this happens, I do it to manage the keyboard when it appears.
More info at the bottom of the document: https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

from masonry.

cloudkite avatar cloudkite commented on July 22, 2024

@lluisgerard that is weird! Did you get it working or did you just go with contentOffset?

from masonry.

lluisgerard avatar lluisgerard commented on July 22, 2024

@cloudkite I'm using setContentOffset by now and getting good results but it's more complicated because I have to calculate it all to get the position.
So far I've seen that some people just use fixed UITableViews to avoid these problems with autolayout and scrollViews.

from masonry.

lluisgerard avatar lluisgerard commented on July 22, 2024

Ok! just found a solution updating your UIScrollView example. Very simple, we create a contentView to add all the views. We still need to add the bottom view though.

#26

from masonry.

mcastro-dev avatar mcastro-dev commented on July 22, 2024

As I couldn't find this solution anywhere else but here, in case someone needs it...

I didn't have to add the footer view.
Just set the bottom constraint of the last view in the scrollview and it works fine.
In the example code above, the last useful view would be the view3.
In Swift:

view3.snp.makeConstraints { make in
        make.top.equalTo(view2.snp.bottom)
        make.left.equalToSuperview()
        make.right.equalToSuperview()
        make.bottom.equalTo(scrollView.snp.bottom).offset(-20)
}

from masonry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.