How to make Image page viewer for images swift ios

13,923

You can do one of the following two things to achieve your goal :

  1. Make a modal segue of the cell to the next UICollectionViewController where the images are showed in full screen, and in the prepareForSegue pass all the data (images) you need to show and where exactly you are in this moment (indexOfImage).
  2. You can watch the didSelectItemAtIndexPath and then pass all the data to one instance of the next UICollectionViewController you want to show with the presentViewController func.

But it's very important that in the next UICollectionViewController you have set pageEnabled = true in code or in the Interface Builder (I though is much easy to do.)

UPDATE:

Very good tutorials on how to make a slide show of images using an UIScrollView or an UICollectionView :

I hope this help you.

Share:
13,923

Related videos on Youtube

MBH
Author by

MBH

Software Engineer, Addicted to writing Mobile Applications for both platforms Android and iOS.

Updated on June 04, 2022

Comments

  • MBH
    MBH almost 2 years

    I wanna display a couple of images from the assets folders, into my application. so I wanna make a page view.

    First, images will be inside collection view, then on click, the image will be full screen. Then the user can slide between the images by swiping right and left as shown in the following photo:

    Description for required lib or sample

    I found this tutorial:

    PhotosGalleryApp

    Updated:

    I have this in my storyboard:

    enter image description here

    Now in GaleryViewController I show the images in cells

    when user click on it, I open the image in fullscreen in PhotoViewController.

    PhotoViewController.swift :

    import UIKit
    
    class PhotoViewController: UIViewController{
    
    
    @IBOutlet weak var imageView: UIImageView!
    
    var index: Int = 0;
    var pageViewController : UIPageViewController?
    
    @IBAction func btnCancelClicked(sender: AnyObject) {
        self.navigationController?.popToRootViewControllerAnimated(true);
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        initUI();
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func viewWillAppear(animated: Bool) {
        self.navigationController?.hidesBarsOnTap = true;
        self.navigationController?.hidesBarsOnSwipe = true;
        displayPhoto()
    }
    
    func initUI() -> Void {
    //        pageViewController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
    //        pageViewController!.dataSource = self
    }
    
    func displayPhoto() {
        self.imageView.image = UIImage(named: Constants.Statics.images[index])
    }
    

    I have the images in static structure so i can access them anywhere:

    class Constants {
    
        struct Statics {
            static let images = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","7.jpg","8.jpg"]
        }
    }
    

    My problem is: I want to add the feature that allow me to swipe between pictures inside the PhotoViewController.

    Any ideas?

    Thank you

    • Victor Sigler
      Victor Sigler about 9 years
      I don't see in any part of your code that you have set the dataSource and delegate of the PageViewController and set the ViewController to implements the protocols UIPageViewControllerDelegate neither UIPageViewControllerDataSource nad without this you can't make a Swipe of any type.
  • Victor Sigler
    Victor Sigler about 9 years
    @MBH I'm put some very good tutorials on how to achieve what do you want, because I'm writing a tutorial on how to do it in Swift but it has not been completed yet, I'll update the answer when I finish it. I hope this help you
  • MBH
    MBH about 9 years
    well this is exactly what i really want, THANK YOU SO MUCH
  • Uma Madhavi
    Uma Madhavi about 7 years
    @VictorSigler.. Can u explain me some more detail to achieve this in swift