IOS View View with Partially Visible Next and Previous Views

I am trying to achieve something like iPhone flash cards. Where some text content will be in the center of the map and the left side of the previous map, the right side of the map will be partially visible.

enter image description here

So far I've tried with nicklockwood / SwipeView from github . But I was unable to get partial visibility of the left / right side of the map.

Is there a work around / library? Please let me know.

Thanks in advance,

+3


source to share


2 answers


I would just use UICollectionView.

Binding: UICollectionView with swap page width

location:



UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(200, 400);
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

      

The nice thing about this, you can easily implement the centering behavior when the user clicks on the left or right partially visible cell (this is not so easy with some UIScrollView hacks):

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self.collectionView scrollToItemAtIndexPath:indexPath
                                atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
                                        animated:YES];
}

      

+3


source


If you want to achieve this with the UIScrollView

pagination api available there is a simple trick. In addition, from installation pagingEnabled

to YES

also make sure the parameter is clipsToBounds

set to NO

.

UIScrollView *scrollView = [UIScrollView new];
self.scrollView.pagingEnabled = YES;
self.scrollView.clipsToBounds = NO;

      

Now you need to set the scroll size to the size of your page. The scrolling view will expand to show other pages.



To be able to start dragging outside of the scroll as well, you need to create a container view that contains the scroll view. Then you override hitTest:

in that container view, watching the scroll all the time:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    return self.scrollView;
}

      

If clipToBounds

set to a value in the container view YES

, this will be the scrolling scope.

+1


source







All Articles