Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBlair Rorani
6,658 PointsHow can I get a new 'fun fact' when I swipe?
I built fun facts to work using the button to trigger a new fact as shown in the course.
How can I change the fun fact by swiping (more like a side scroll) vs. using the button?
Thanks in advance.
1 Answer
Dimitris Sotiris Tsolis
28,141 PointsA simple way to implement this functionality is to add gesture recognizer to the view controller's view. First, create a new method to handle the swipe event.
func swipeRecognizer(recognizer: UISwipeGestureRecognizer) {
self.showFunFact()
}
Then, in the viewDidLoad method, after "super.viewDidLoad()" you have to instantiate a new swipe recognizer, define it's direction and finally add it to the view.
let swipeLeft = UISwipeGestureRecognizer(target: self, action: "swipeRecognizer:")
swipeLeft.direction = UISwipeGestureRecognizerDirection.Left
self.view.addGestureRecognizer(swipeLeft)
shaunbaker04
1,719 PointsMan that's cool to know! I am learning and went ahead and implemented your code for the swipe life gesture and it works flawless. Nice tidbit of code that allowed me to practice a new function. It is cool to see the possibilities of what we can do with this iOS devices....
Michael McKenna
3,451 PointsMichael McKenna
3,451 PointsYou are better off going to stackoverflow.com for questions like this.
And unfortunately I do not have an answer to your problem, but there are a lot of smart people on stackoverflow that will be more than willing to help you!