How to make Image page viewer for images swift ios
You can do one of the following two things to achieve your goal :
- Make a modal segue of the cell to the next
UICollectionViewController
where the images are showed in full screen, and in theprepareForSegue
pass all the data (images) you need to show and where exactly you are in this moment (indexOfImage
). - You can watch the
didSelectItemAtIndexPath
and then pass all the data to one instance of the nextUICollectionViewController
you want to show with thepresentViewController
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
:
- How To Use UIScrollView to Scroll and Zoom Content
- Creating a Paged Photo Gallery With a UICollectionView
I hope this help you.
Related videos on Youtube
MBH
Software Engineer, Addicted to writing Mobile Applications for both platforms Android and iOS.
Updated on June 04, 2022Comments
-
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:
I found this tutorial:
Updated:
I have this in my storyboard:
Now in
GaleryViewController
I show the images in cellswhen 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 about 9 yearsI 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 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 about 9 yearswell this is exactly what i really want, THANK YOU SO MUCH
-
Uma Madhavi about 7 years@VictorSigler.. Can u explain me some more detail to achieve this in swift