Bernard
Bernard

Reputation: 4580

How to have scrollable page view to swipe left and right?

I have an apllication which read multiple images and description for images through web server. Number of images are variable.

I want to have a VC and in middle of VC I want to have a scrollable view which user can swipe left and right for each picture and chose their own picture.

Most important is when view show pictures I need to show one picture completely and on each sides I must show half of the left and right image.

Number of images are not more than 10 but change everytime.

When they click on each picture it will go to another VC and dose specific actions. Therefore, pictures are like a buttons with an action. Number of pictures everytime changes so I must have some type of container to dynamicaly read picture and display them.

Can I use PageViewController in dynamic way or I use Scroll View?

I appreciate if anyone can suggest me best methodology to implement this VC.

Upvotes: 0

Views: 69

Answers (2)

Ajayattri
Ajayattri

Reputation: 1

In view did load you can Add this for collection view with pagging:

  UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
    layout.minimumInteritemSpacing = 0;
    if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
        layout.minimumLineSpacing = 0;

    }
    else
    {
        layout.minimumLineSpacing = 0;

    }
    layout.scrollDirection=UICollectionViewScrollDirectionHorizontal;
    _collectionView=[[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];

    [_collectionView setDataSource:self];
    [_collectionView setDelegate:self];
    [_collectionView setBackgroundColor:[UIColor clearColor]];
    [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"];


    _collectionView.pagingEnabled = YES;


    [self.view addSubview:_collectionView];


    self.pageControl=[[UIPageControl alloc]init];
    [self.view addSubview: self.pageControl ];

then you have to enter enter page size like this

self.pageControl.frame=CGRectMake([UIScreen mainScreen].bounds.size.width/2, _collectionView.frame.size.height+_collectionView.frame.origin.y+20, 20, 20);

[_collectionView reloadData]; thats it Done.

Upvotes: 0

Rafał Sroka
Rafał Sroka

Reputation: 40030

You don't need UIPageViewController for it.

Best way to implement this would be to use UICollectionView with horizontal scrolling and paging enabled.

Upvotes: 1

Related Questions