MBH*_*MBH 3 uiimageview uiimage ios uipageviewcontroller swift
我想在资产文件夹中显示几个图像到我的应用程序中.所以我想做一个页面视图.
首先,图像将在集合视图内,然后单击,图像将全屏显示.然后,用户可以通过向右和向左滑动来在图像之间滑动,如下图所示:

我找到了这个教程:
更新:
我在故事板中有这个:

现在,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])
}
Run Code Online (Sandbox Code Playgroud)
我有静态结构的图像,所以我可以在任何地方访问它们:
class Constants {
struct Statics {
static let images = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","7.jpg","8.jpg"]
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:我想添加允许我在内部图片之间滑动的功能PhotoViewController.
有任何想法吗?
谢谢
您可以执行以下两项操作之一来实现目标:
UICollectionViewController全屏显示图像的下一个单元格,并在prepareForSegue传递中显示您需要显示的所有数据(图像)以及此时的确切位置(indexOfImage).didSelectItemAtIndexPath,然后将所有数据传递给UICollectionViewController您要使用presentViewControllerfunc 显示的下一个实例.但是非常重要的是,在接下来UICollectionViewController你已经设置pageEnabled = true了代码或在Interface Builder中(我很容易做到.)
更新:
关于如何使用UIScrollView或者以下方式制作图像幻灯片的非常好的教程UICollectionView:
我希望这对你有帮助.
| 归档时间: |
|
| 查看次数: |
12515 次 |
| 最近记录: |