Hi at all, I have a little problem with autolayout, I have a custom UIView with some view, one of this view is called view_A, now I need to add n scrollview in the same position, one upon the other, this scrollview have a content view inside with n subview, for do this I write this code:
the problem is that scrollView & scrollViewContanto have frame = 0, so everything inside it isn't clickable, where is the mistake?
Code:
- (void) initProducts
{
for (int i=0; i<_collezioni.count;i++)
{
Page *collezione = [_collezioniobjectAtIndex:i];
UIScrollView *scrollView = [[UIScrollViewalloc] init];
[scrollView setTag:100 + collezione._id];
[_productsViewaddSubview:scrollView];
UIView *scrollViewContent = [[UIViewalloc] init];
[scrollViewContent setBackgroundColor:[UIColorredColor]];
[scrollView addSubview:scrollViewContent];
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
scrollViewContent.translatesAutoresizingMaskIntoConstraints = NO;
id views = @{
@"scrollView": scrollView,
@"scrollViewContent": scrollViewContent
};
[_productsViewaddConstraints:[NSLayoutConstraintconstraintsWithVisualFormat: @"H:|[scrollView]|"options:0metrics:nilviews:views]];
[_productsViewaddConstraints:[NSLayoutConstraintconstraintsWithVisualFormat: @"V:|[scrollView]|"options:0metrics:nilviews:views]];
[_productsViewaddConstraints:[NSLayoutConstraintconstraintsWithVisualFormat: @"H:|[scrollViewContent]|"options:0metrics:nilviews:views]];
[_productsViewaddConstraints:[NSLayoutConstraintconstraintsWithVisualFormat: @"V:|[scrollViewContent]|"options:0metrics:nilviews:views]];
NSMutableDictionary *dictProdotti = [NSKeyedUnarchiverunarchiveObjectWithData:[_userobjectForKey:KEY_PRODOTTI]];
NSMutableArray *prodotti = [dictProdotti objectForKey:[NSStringstringWithFormat: @"%d",collezione._id]];
int count = 0;
for (Page *page in prodotti)
{
SingleProduct *singleProduct = [[SingleProductalloc] initWithFrame:CGRectMake(_productsView.frame.size.height * count, 0,
_productsView.frame.size.height,
_productsView.frame.size.height - 40)];
[singleProduct setTranslatesAutoresizingMaskIntoConstraints:YES];
[singleProduct setTag:100 + page._id];
[singleProduct setProdotto:page];
[singleProduct setDelegate:self];
[scrollViewContent addSubview:singleProduct];
count++;
}
[scrollViewContent setFrame:CGRectMake(0, 0, _productsView.frame.size.height, _productsView.frame.size.height)];
[scrollView setContentSize:CGSizeMake(prodotti.count * _productsView.frame.size.height, _productsView.frame.size.height)];
}
}
the problem is that scrollView & scrollViewContanto have frame = 0, so everything inside it isn't clickable, where is the mistake?