autolayout uiscrollview problem

Discussion in 'iOS Programming' started by kikko088, Jul 19, 2015.

  1. kikko088 macrumors member

    Oct 13, 2010
    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:

    - (void) initProducts
        for (int i=0; i<_collezioni.count;i++)
            Page  *collezione = [_collezioniobjectAtIndex:i];
            UIScrollView *scrollView = [[UIScrollViewalloc] init];
            [scrollView setTag:100 + collezione._id];
            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 - 40)];
                [singleProduct setTranslatesAutoresizingMaskIntoConstraints:YES];
                [singleProduct setTag:100 + page._id];
                [singleProduct setProdotto:page];
                [singleProduct setDelegate:self];
                [scrollViewContent addSubview:singleProduct];
    [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?
  2. bjet767 macrumors 6502a

    Oct 2, 2010
    In iOS the top view is the current view or the one you can click on.

    Why do you need the views stacked like this?

    The only time I have done such a thing was to build a single view controller which contained two views. One of the views was to be hidden (by the view on top of it) unless the user selects an item from the bar. What I did then was to make the top view hidden.

    The code I use is really simple, "self.someView.hidden = YES;"

    When the user is done with the underlying view simple unhide the top view, "self.someView.hidden = NO; All touch response returns to that view.

Share This Page