我想在单击集合视图中的图像时,除了该图像之外,它将导致所有内容隐藏。我已将标签手势拖动到图像视图中,并为其设置操作,但不会调用它。我不知道为什么,以及如何实现这一点。
这是我的代码:
import Foundation
import UIKit
import AAShareBubbles
import SwipeView
class PhotoDetailViewController: UIViewController, AAShareBubblesDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet var collectionView: UICollectionView!
@IBOutlet var topView: UIView!
@IBOutlet var bottomView: UIView!
var checkTapGestureRecognize = true
var selectedIndexPath: NSIndexPath?
override func viewDidLoad() {
title = "Photo Detail"
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if let selectedIndexPath = selectedIndexPath {
collectionView.scrollToItemAtIndexPath(selectedIndexPath, atScrollPosition: UICollectionViewScrollPosition.CenteredHorizontally, animated: false)
}
}
// MARK: Collection
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return images.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("DetailCell", forIndexPath: indexPath) as! PhotoCollectionDetailViewCell
cell.photoDetailImageView.image = UIImage(named: images[indexPath.row])
cell.photoDetailImageView.alpha = 0
let millisecondDelay = UInt64(arc4random() % 600) / 1000
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(millisecondDelay * NSEC_PER_SEC)), dispatch_get_main_queue(),({ () -> Void in
UIView.animateWithDuration(0.5, animations: ({
cell.photoDetailImageView.alpha = 1.0
}))
}))
return cell
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let screenSize: CGRect = UIScreen.mainScreen().bounds
return CGSizeMake(screenSize.width, screenSize.height - topView.frame.height - bottomView.frame.height)
}
override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
collectionView.reloadData()
}
// MARK: OnBack
@IBAction func onBackClicked(sender: AnyObject) {
self.navigationController?.popViewControllerAnimated(true)
}
// MARK: onTabGesture ImageView
@IBAction func onTabGestureRecognize(sender: UITapGestureRecognizer) {
print("on tap")
if checkTapGestureRecognize == true {
bottomView.hidden = true
topView.hidden = true
self.navigationController?.navigationBarHidden = true
let screenSize: CGRect = UIScreen.mainScreen().bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height
collectionView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)
checkTapGestureRecognize = false
showAminationOnAdvert()
}
else if checkTapGestureRecognize == false {
bottomView.hidden = false
topView.hidden = false
self.navigationController?.navigationBarHidden = false
checkTapGestureRecognize = true
}
}
func showAminationOnAdvert() {
let transitionAnimation = CATransition();
transitionAnimation.type = kCAEmitterBehaviorValueOverLife
transitionAnimation.subtype = kCAEmitterBehaviorValueOverLife
transitionAnimation.duration = 2.5
transitionAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transitionAnimation.fillMode = kCAFillModeBoth
collectionView.layer.addAnimation(transitionAnimation, forKey: "fadeAnimation")
}
@IBAction func onShareTouched(sender: AnyObject) {
print("share")
let myShare = "I am feeling *** today"
let shareVC: UIActivityViewController = UIActivityViewController(activityItems: [myShare], applicationActivities: nil)
self.presentViewController(shareVC, animated: true, completion: nil)
}
@IBAction func playAutomaticPhotoImages(sender: AnyObject) {
animateImages(0)
}
func animateImages(no: Int) {
var number: Int = no
if number == images.count - 1 {
number = 0
}
let name: String = images[number]
self.collectionView!.alpha = 0.5
//self.collectionView.cellForItemAtIndexPath(NSIndexPath(index: number)) = UIImage(named: name)
//code to animate bg with delay 2 and after completion it recursively calling animateImage method
UIView.animateWithDuration(2.0, delay: 0.8, options:UIViewAnimationOptions.CurveEaseInOut, animations: {() in
self.collectionView!.alpha = 1.0;
},
completion: {(Bool) in
number++;
self.animateImages(number);
print(String(images[number]))
})
}
}
答案 0 :(得分:2)
cell.photoDetailImageView.image = UIImage(named: images[indexPath.row])
cell.photoDetailImageView.alpha = 0
cell.photoDetailImageView.userInteractionEnabled=YES
答案 1 :(得分:1)
尝试在UserInteractionEnabled
true
设置为imageView
答案 2 :(得分:1)
对我来说看起来像是一个简单的拼写错误。
在我第一次检查时,onTabGestureRecognize:
可能需要onTapGestureRecognize:
但是当我将新的TapGestureRecognizer添加到我自己的项目并尝试将其连接到图像视图时,我看到的唯一发送动作可能是调用选择器。该选择器将是您在点击图像视图时要触发的功能。