已关闭::使用滑动和点按手势创建UIButton水平轮播

时间:2015-02-10 21:38:09

标签: ios swift uibutton uipangesturerecognizer uitapgesturerecognizer

在VC内部,我试图找出如何让UIButton识别水平滑动,然后点按。

有一系列文字。

var plotList = ["stuff", "to do", "this", "or that"]

默认显示为plotList [0]。

旋转木马在无限循环中重复不会在阵列末端停止。

当用户仅按下按钮时,我不希望VC的其他组件对此特定滑动作出反应,我希望按钮显示plotList字符串。

当用户点击按钮时,我想将结果推送到一个开关,该开关将启动相应的UIView。

我想避免使用这种UILabel / UIButton组合。请参阅Handling Touch Event in UILabel and hooking it up to an IBAction

到目前为止我在这里

import UIKit

class carouselVC: UIViewController {


  @IBOutlet var carouselView: UIView!
  @IBOutlet var labelOutlet: UILabel!
  @IBOutlet var buttonOutlet: UIButton!

  var plotList = ["stuff", "this", "that"]

  let swipeRec = UISwipeGestureRecognizer()


  override func viewDidLoad() {
    super.viewDidLoad()
    var swipeButtonLeft: UISwipeGestureRecognizer =
    UISwipeGestureRecognizer(target: self, action: "buttonLeft")
    swipeButtonLeft.direction = UISwipeGestureRecognizerDirection.Left
    self.buttonOutlet.addGestureRecognizer(swipeButtonLeft)

    var swipeButtonRight: UISwipeGestureRecognizer =
    UISwipeGestureRecognizer(target: self, action: "buttonRight")
    swipeButtonRight.direction = UISwipeGestureRecognizerDirection.Right
    self.buttonOutlet.addGestureRecognizer(swipeButtonRight)

  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
  }

  func buttonLeft(){
    println("buttonLeft")
  }
  func buttonRight(){
    println("buttonRight")
  }

  @IBAction func buttonAction(sender: UIButton) {
    sender.setTitle(plotList[1], forState: .Normal)
  }
}

任何帮助?

1 个答案:

答案 0 :(得分:1)

使用带有UILabel的UIView,而不是按钮。在UILabel上添加UIView并使其颜色清晰。您可以使UIlabel看起来像一个按钮。在其上添加滑动手势/点按手势。并且在手势的动作中做任何操作。