Reputation: 16619
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 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
Upvotes: 3
Views: 14612
Reputation: 23449
You can do one of the following two things to achieve your goal :
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
).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.
Upvotes: 8