Disable ScrollView scrolling
In my application, I was setting the height of the UIScrollView programmatically to 70.0:
I need to dynamically set the width of the scrollView depending on the number of images I added, which I do like this:
int imageScrollerWidth = ([self.setSpins count]+1) * (int)([self.imageDimensions[@"width"] integerValue] + 5);
[self.spinScrollView setContentSize:CGSizeMake(imageScrollerWidth, self.spinScrollView.frame.size.height)];
self.spinScrollView.contentOffset = CGPointZero;
But when I open the view on my phone, it seems that I can scroll both vertically and horizontally:
Since the scrollView size is 70 I didn't think vertical scrolling would be enabled. How do I turn off vertical scrolling?
source to share
Using a CollectionView might do the trick. The implementation is pretty straight forward. As a plus, you get a method - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
to get the selected image.
These are the required methods:
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 30;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CellectionCell" forIndexPath:indexPath];
[cell addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.jpg"]]];
return cell;
}
and on the storyboard you have to change the scroll orientation
source to share