
- iOS Tutorial
- iOS - Home
- iOS - Getting Started
- iOS - Environment Setup
- iOS - Objective-C Basics
- iOS - First iPhone Application
- iOS - Actions and Outlets
- iOS - Delegates
- iOS - UI Elements
- iOS - Accelerometer
- iOS - Universal Applications
- iOS - Camera Management
- iOS - Location Handling
- iOS - SQLite Database
- iOS - Sending Email
- iOS - Audio & Video
- iOS - File Handling
- iOS - Accessing Maps
- iOS - In-App Purchase
- iOS - iAd Integration
- iOS - GameKit
- iOS - Storyboards
- iOS - Auto Layouts
- iOS - Twitter & Facebook
- iOS - Memory Management
- iOS - Application Debugging
- iOS Useful Resources
- iOS - Quick Guide
- iOS - Useful Resources
- iOS - Discussion
How to detect swipe vertically on a ScrollView using Swift?
To detect swipe in scrollView we will need to make use of some tricks as scroll view does not natively give the directions of scroll made on it. We’ll see this with help of an example.
Create an empty project, add scroll view to the view as per your requirement.
Give them constraint as required in the application.
From the object library, drag and drop a swipe gesture recognizer right above the Scroll View.
Select the gesture recognizer, go to its attribute inspector and from there, select the swipe option and set the value as “up”.
When you do this, now your gesture recognizer can recognize up swipes only. Now you need to create a method for this swipe gesture.
@IBAction func swipeMade(_ sender: UISwipeGestureRecognizer) { if sender.direction == .up { print("up swipe made") // perform actions here. } }
When you write this code, the recognizer sends events to this method, and if the swipe direction is up, it will come inside the if block. You can perform your desired operation here.
When we run this code on a device and make a swipe, below is the result that’s produced on the console.
- Related Articles
- How to detect end of ScrollView in Android?
- How to detect shake gesture using Swift?
- How to detect swipe direction between left/right and up/down in Android using Kotlin?
- How to detect swipe direction between left/right and up/down in Android?
- How to center a Text object vertically on canvas using FabricJS?
- How to put a ListView into a ScrollView without it collapsing on Android?
- How to detect pressing Enter on keyboard using jQuery?
- How to create a swipe refresh layout in Android using Kotlin?
- How to handle right-to-left and left-to-right swipe gestures on Android using Kotlin?
- How to Detect if CAPS Lock is ON using JavaScript?
- How to use Swift to detect when AVPlayer video ends playing?
- How to center a Text object horizontally and vertically on canvas using FabricJS?
- How to put a ListView into a ScrollView without it collapsing on Android in Kotlin?
- How to flip a Circle vertically using FabricJS?
- How to flip a Triangle vertically using FabricJS?
