0
在一個VC內部,我試圖弄清楚如何讓UIButton
識別水平滑動,然後點擊。有一組文本。關閉::創建一個用刷卡和輕擊手勢的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)
}
}
任何幫助嗎?
我一直在黑客通過這個例子,並認爲我需要弗蘭肯斯坦這樣的東西'http:// stackoverflow.com/questions/28059381 /添加手勢到按鈕在迅速' – 2015-02-10 21:45:46