首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何实现SwipeView?

如何实现SwipeView?
EN

Stack Overflow用户
提问于 2015-12-11 14:32:41
回答 1查看 1.2K关注 0票数 0

我想滑动每个图像切换到另一个图像,如画廊应用程序。我现在正在使用这个https://github.com/nicklockwood/SwipeView,但是我不知道如何实现它。是在PhotoDetailViewController中拖动集合视图,还是只在编码中使用集合视图。希望有人能帮我这个忙。

这是我的代码:

代码语言:javascript
复制
import Foundation
import UIKit
import AAShareBubbles
import SwipeView

class PhotoDetailViewController: UIViewController, AAShareBubblesDelegate, SwipeViewDataSource, SwipeViewDelegate {


  @IBOutlet var topView: UIView!
  @IBOutlet var bottomView: UIView!
  @IBOutlet var photoImageView: UIImageView!
  var photoImage = UIImage()
  var checkTapGestureRecognize = true
  var swipeView: SwipeView = SwipeView.init(frame: CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: UIScreen.mainScreen().bounds.height))

  override func viewDidLoad() {

    title = "Photo Detail"
    super.viewDidLoad()
    photoImageView.image = photoImage
    swipeView.dataSource = self
    swipeView.delegate = self
    let swipe = UISwipeGestureRecognizer(target: self, action: "swipeMethod")
    swipeView.addGestureRecognizer(swipe)
    swipeView.addSubview(photoImageView)
    swipeView.pagingEnabled = false
    swipeView.wrapEnabled = true

  }

  func swipeView(swipeView: SwipeView!, viewForItemAtIndex index: Int, reusingView view: UIView!) -> UIView! {
    return photoImageView
  }

  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("SwipeCell", forIndexPath: indexPath) as! SwipeViewPhotoCell
    return cell
  }

  @IBAction func onBackClicked(sender: AnyObject) {
    self.navigationController?.popViewControllerAnimated(true)
  }


  @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
      photoImageView.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
    photoImageView.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)
    //    print("share bubles")
    //    let shareBubles: AAShareBubbles = AAShareBubbles.init(centeredInWindowWithRadius: 100)
    //    shareBubles.delegate = self
    //    shareBubles.bubbleRadius = 40
    //    shareBubles.sizeToFit()
    //    //shareBubles.showFacebookBubble = true
    //    shareBubles.showTwitterBubble = true
    //    shareBubles.addCustomButtonWithIcon(UIImage(named: "twitter"), backgroundColor: UIColor.whiteColor(), andButtonId: 100)
    //    shareBubles.show()

  }

  @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.photoImageView!.alpha = 0.5
    self.photoImageView!.image = 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.photoImageView!.alpha = 1.0;
      },
      completion: {(Bool) in
        number++;
        self.animateImages(number);
        print(String(images[number]))
    })
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-11 14:52:01

只需将一个UIView拖放到您的情节提要/XIB中,并将其自定义类设置为SwipeView。

还将委托和数据源设置为视图控制器,其中包括刚才拖动的UIView。

然后,在视图控制器中,实现所需的委托方法,类似于如何实现表视图的方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34225885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档