Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with UIView in UIScrollView #12

Closed
fab-jul opened this issue Aug 28, 2013 · 3 comments
Closed

Problem with UIView in UIScrollView #12

fab-jul opened this issue Aug 28, 2013 · 3 comments

Comments

@fab-jul
Copy link

fab-jul commented Aug 28, 2013

Hi there

First of all, thanks for Masonry, it looks really awesome! Unfortunately though, I have the following problem: I created a UIScrollView inside the UIView of my UIViewController and added some constraints to keep the scroll view the size of the view:

self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
_scrollView.backgroundColor = [UIColor redColor];
[self.view addSubview:_scrollView];

[_scrollView makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(self.view);
}];

This seems to work, but then I added a UIView inside the scroll view and tried to make it stick to the top:

UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.backgroundColor = [UIColor blueColor];
[_scrollView addSubview:view];

[view makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(@0);
    make.left.equalTo(@0);
    make.right.equalTo(@0);
    make.height.equalTo(@100);
}]; 

However, this second view never shows up! Any idea on what I'm doing wrong?

@fab-jul
Copy link
Author

fab-jul commented Aug 28, 2013

Ok got it! I had to replace

 make.right.equalTo(@0);

with

make.width.equalTo(_scrollView.width);

Not sure why though, I guess I'll have to look into Auto Layout some more

@fab-jul fab-jul closed this as completed Aug 28, 2013
@cloudkite
Copy link
Contributor

UIScrollView has a few quirks when used with Auto Layout. See https://developer.apple.com/library/ios/technotes/tn2154/_index.html

@frkd-dev
Copy link

I think this case should be noted in docs, since it's non obvious. I spent several hours to figure out what's wrong with scrollview...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants