3

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
  • 23,243
  • 14
  • 88
  • 105
MBH
  • 16,271
  • 19
  • 99
  • 149
  • 1
    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 Mar 15 '15 at 19:55
  • @VictorSigler thats what i was trying to find out, Actually i started swift after 3 years of android development, there i used Pager to implement the same thing, thank you for the help – MBH Mar 15 '15 at 22:26
  • @VictorSigler You may put it as an answer i will accept it for the question – MBH Mar 15 '15 at 22:28
  • I going to update my answer to handle the slideShow , don't worry – Victor Sigler Mar 15 '15 at 22:29

1 Answers1

8

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.

Victor Sigler
  • 23,243
  • 14
  • 88
  • 105
  • my main problem is to perform the swipe left and right actions to show the next and previous picture, all other things work fine for me – MBH Mar 15 '15 at 19:26
  • @you have set `pageEnabled = true` in the `UICollectionView` ? Please share more code then. – Victor Sigler Mar 15 '15 at 19:27
  • 1
    @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 – Victor Sigler Mar 15 '15 at 22:42
  • well this is exactly what i really want, THANK YOU SO MUCH – MBH Mar 15 '15 at 22:44
  • @VictorSigler.. Can u explain me some more detail to achieve this in swift – Uma Madhavi Feb 14 '17 at 09:44