首先,图像将在集合视图内,然后单击,图像将全屏显示.然后,用户可以通过向右和向左滑动来在图像之间滑动,如下图所示:
我找到了这个教程:
PhotosGalleryApp
更新:
我在故事板中有这个:
现在在GaleryViewController中我在单元格中显示图像
当用户点击它时,我在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])
}
我有静态结构的图像,所以我可以在任何地方访问它们:
class Constants {
struct Statics {
static let images = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","7.jpg","8.jpg"]
}
}
我的问题是:我想添加允许我在PhotoViewController内的图片之间滑动的功能.
有任何想法吗?
谢谢
您可以执行以下两项操作之一来实现目标:>将单元格的模态segue设置为下一个UICollectionViewController,其中图像以全屏显示,并在prepareForSegue中传递您需要显示的所有数据(图像)以及此时的确切位置(indexOfImage).
>您可以观看didSelectItemAtIndexPath,然后将所有数据传递给您想要使用presentViewController func显示的下一个UICollectionViewController的一个实例.
但是在下一个UICollectionViewController中你已经在代码或Interface Builder中设置了pageEnabled = true非常重要(我觉得很容易).
UPDATE:
关于如何使用UIScrollView或UICollectionView进行图像幻灯片放映的非常好的教程:
> How To Use UIScrollView to Scroll and Zoom Content
> Creating a Paged Photo Gallery With a UICollectionView
我希望这对你有帮助.
