繁体   English   中英

在CollectionView单元格中的视图上的TabGesture

[英]TabGesture on View in Cell in CollectionView

我想当我在“收藏夹视图”中单击图像时,它将导致除该图像以外的所有图像都被隐藏。 我已将一个标签手势拖到图像视图中,并为其设置了一个动作,但未调用它。 我不知道为什么,以及如何实现这样的目标。

在此处输入图片说明

在此处输入图片说明

这是我的代码:

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]))
    })
  }


}
cell.photoDetailImageView.image = UIImage(named: images[indexPath.row])
cell.photoDetailImageView.alpha = 0
cell.photoDetailImageView.userInteractionEnabled=YES

尝试设置UserInteractionEnabledtrueimageView

看起来像一个简单的拼写错误给我。

在我的第一次检查中, onTabGestureRecognize:可能需要onTapGestureRecognize:

但是,当我在自己的项目中添加新的TapGestureRecognizer并尝试将其连接到图像视图时,我看到的唯一发送动作的可能性是调用选择器。 该选择器将是您在点击图像视图时要触发的功能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM