我使用MVCarouselCollectionView框架作为图片库 如果它是初始的故事板,则查看仅适用的照片库 项目链接:link download code
如果我将图库视图作为初始视图,它将起作用。但是,如果我把她作为第二个视图并使用以下/推动将无法正常工作
图库代码
import UIKit
import MVCarouselCollectionView
import QuartzCore
import Alamofire
class GaleriaDeFotosViewController: UIViewController, MVCarouselCollectionViewDelegate {
@IBOutlet var pageControl: UIPageControl!
@IBOutlet var collectionView : MVCarouselCollectionView!
var imagePaths : [String] = []
// Closure to load local images with UIImage.named
var imageLoader: ((imageView: UIImageView, imagePath : String, completion: (newImage: Bool) -> ()) -> ()) = {
(imageView: UIImageView, imagePath : String, completion: (newImage: Bool) -> ()) in
imageView.image = UIImage(named:imagePath)
completion(newImage: imageView.image != nil)
}
@IBAction func BtnCarregar(sender: AnyObject) {
configureCollectionView()
carregaFotoModo1()
}
override func viewDidLoad() {
super.viewDidLoad()
configureCollectionView()
carregaFotoModo1()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func configureCollectionView() {
view.setTranslatesAutoresizingMaskIntoConstraints(false)
self.pageControl.numberOfPages = imagePaths.count
collectionView.selectDelegate = self
collectionView.imagePaths = imagePaths
collectionView.commonImageLoader = self.imageLoader
collectionView.maximumZoom = 2.0
collectionView.pagingEnabled = true
collectionView.reloadData()
}
// MARK: MVCarouselCollectionViewDelegate
func carousel(carousel: MVCarouselCollectionView, didSelectCellAtIndexPath indexPath: NSIndexPath) {
// Do something with cell selection
}
func carousel(carousel: MVCarouselCollectionView, didScrollToCellAtIndex cellIndex : NSInteger) {
// Page changed, can use this to update page control
self.pageControl.currentPage = cellIndex
}
func addAsChildViewController(parentViewController : UIViewController, attachToView parentView: UIView)
{
parentViewController.addChildViewController(self)
self.didMoveToParentViewController(parentViewController)
parentView.addSubview(self.view)
self.autoLayout(parentView)
}
func autoLayout(parentView: UIView) {
self.matchLayoutAttribute(.Left, parentView:parentView)
self.matchLayoutAttribute(.Right, parentView:parentView)
self.matchLayoutAttribute(.Bottom, parentView:parentView)
self.matchLayoutAttribute(.Top, parentView:parentView)
}
func matchLayoutAttribute(attribute : NSLayoutAttribute, parentView: UIView) {
parentView.addConstraint(
NSLayoutConstraint(item:self.view, attribute:attribute, relatedBy:NSLayoutRelation.Equal, toItem:parentView, attribute:attribute, multiplier:1.0, constant:0))
}
// MARK: FullScreenViewControllerDelegate
func willCloseWithSelectedIndexPath(indexPath: NSIndexPath) {
self.collectionView.resetZoom()
self.collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition:UICollectionViewScrollPosition.CenteredHorizontally, animated:false)
}
func carregaFotoModo1()
{
self.imageLoader = imageViewLoadFromPath
self.imagePaths = [
"http://li.zoocdn.com/bb3d7c42506f563c1174828c97522728a87cfae8_645_430.jpg",
"http://li.zoocdn.com/162fd32ce15911cba3dcdf27a8a37238708991bc_645_430.jpg",
"http://li.zoocdn.com/9e17e58963944f4a6695c56561f1bd4ee0803cba_645_430.jpg",
"http://li.zoocdn.com/ffdbb7c884427a1d599f052cae4f205bf63373cf_645_430.jpg",
]
println(self.imagePaths)
self.configureCollectionView()
}
}