ios - Closed::Creating a UIButton horizo​​ntal carousel with swipe and tap 手势

标签 ios swift uibutton uipangesturerecognizer uitapgesturerecognizer

在 VC 内部,我试图弄清楚如何让 UIButton 识别水平滑动,然后点击。

有一个文本数组。

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

默认显示为plotList[0]。

无限循环中的轮播不会停在数组的末尾。

当用户仅在按钮上滑动时,我不希望 VC 的其他组件对这个特定的滑动使用react,我希望按钮显示 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)
  }
}

有什么帮助吗?

最佳答案

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

关于ios - Closed::Creating a UIButton horizo​​ntal carousel with swipe and tap 手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28442292/

相关文章:

iphone - 对 <UINavigationController : 0xa98e050> 的开始/结束外观转换的不平衡调用

swift - 在 Swift 3 中以编程方式设置内容过滤器

ios - objective-c 中的“自定义”按钮

ios - UITableViewCell 中的圆形按钮

ios - 在 Xcode 中通过 git 添加新文件的问题

ios - iOS 8/7 UIWindow具有UIWindowLevelStatusBar旋转问题

ios - 从运行时可见的标签中获取字符串

ios - 当我更改约束的优先级时,更改不会使用 UpdateconstraintIfNeeded 进行动画处理

iphone - 为 UINavigationBar 上的后退按钮设置自定义图像

iphone - ios 配置门户中的 "Managed by Xcode"配置文件是什么?它是如何创建的?