在 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 horizontal carousel with swipe and tap 手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28442292/