/ / Swift: zmena zobrazenia v systéme iOS pomocou prejdenia prstom - ios, swift, uiview, gestá prejdením prstom

Swift: Zmena zobrazenia iOS pomocou gesta - ios, swift, uiview, gestá

Som nový v oblasti vývoja iOS.

Ako môžem implementovať gesto prejdenia prstom, aby som zmenil pohľad na sem a tam? Najlepším príkladom, ktorý som doteraz videl, je aplikácia Soundcloud, ale nedokázal som zistiť, ako to dosiahnuť.

odpovede:

7 pre odpoveď č. 1

Použite tento kód ...

override func viewDidLoad() {
super.viewDidLoad()

var swipeRight = UISwipeGestureRecognizer(target: self, action: "respondToSwipeGesture:")
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
self.view.addGestureRecognizer(swipeRight)


}

func respondToSwipeGesture(gesture: UIGestureRecognizer) {

if let swipeGesture = gesture as? UISwipeGestureRecognizer {

switch swipeGesture.direction {

case UISwipeGestureRecognizerDirection.Right:

println("Swiped right")

//change view controllers

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

let resultViewController = storyBoard.instantiateViewControllerWithIdentifier("StoryboardID") as ViewControllerName

self.presentViewController(resultViewController, animated:true, completion:nil)



default:
break
}
}
}

0 pre odpoveď č. 2

UISwipeGestureRecognizer môžete do svojho UIView pridať a pridať k tomuto gestu cieľ a akciu, ktorá sa má vykonať, keď sa gesto objaví

 var swipeGesture = UISwipeGestureRecognizer(target: self, action: "doSomething")
myView.addGestureRecognizer(swipeGesture)

func doSomething() {

// change your view"s frame here if you want
}

-1 pre odpoveď č. 3

Tento tutoriál vám môže pomôcť: http://www.avocarrot.com/blog/implement-gesture-recognizers-swift/

V zásade musíte do svojho zobrazenia pridať rozpoznávač gest, ktorý počúva gestá prejdené prstom. Keď potom zistí prejdenie prstom, prejdite na ďalšie zobrazenie.