Gestures UIGestureRecognizer.

Slides:



Advertisements
Similar presentations
View-Based Application Development Lecture 1 1. Flows of Lecture 1 Before Lab Introduction to the Game to be developed in this workshop Comparison between.
Advertisements

Table Views UITableView. Overview Table view basics Tables display lists of data Each item in a tables list is a row Tables can have an unlimited number.
Detecting Collisions CSE 391 Fall 2012 Tony Scarlatos.
Welcome to SMART Notebook TM 10.7 Review features and functions and get started quickly To access this tutorial later, go to: SMART Notebook Quick-Start.
Anatomy of an iPhone Application Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
View Controllers (second part) Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Button click handlers Maarten Pennings. Introduction An activity has one or more views – view is also known as widget or control – examples include Button,
Storyboards Managing multiple views. Overview Create a single view application Give the project a name and click “Use Storyboards” and “Use Automatic.
Introduction to Apps Development for the iPhone and the Android OS Art Gittleman Professor, Computer Science Calif State Univ Long Beach Feb 28, 2011.
Working with SharePoint Document Libraries. What are document libraries? Document libraries are collections of files that you can share with team members.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Sprite Animation CSE 391 Fall 2012 Tony Scarlatos.
Refactoring Moving a console app to a UI app. Refactoring Goal: change a console app to a UI app Principles: The main.m goes away The local variables.
Xcode Presentation Tom Pletzke. Creating App from template Launch Xcode Select Tabbed Application.
Xcode testing Using XCTest.
Derived from Kirill Muzykov’s Rocket Mouse Tutorial WakeUpAndCode.com.
© 2010 MediaMind Technologies Inc. | All rights reserved Trafficking Media Plan, Ad Attachments & URL Assignments.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
iOS components in Swift
Chapter 10 Fireworks: Part II The Web Warrior Guide to Web Design Technologies.
Object-Oriented Analysis & Design Subversion. Contents  Configuration management  The repository  Versioning  Tags  Branches  Subversion 2.
Chapter 7: Reveal! Displaying Pictures in a Gallery.
Creating Buttons – Lesson 51 Creating Buttons Lesson 5.
Tabbed Views UITabBarController. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and.
Navigation in iPads splitViewController. Overview Create a Master-Detail application Switch Device Family to iPad Give the project a name and click “Use.
IOS with Swift Hello world app.
Managing Multiple Views and Segues FA 172 Intro to Mobile App Development.
Create a Web View App Step-by-Step. Step 1 Create a new project in XCode using the "Single View Application" option.
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Level 1 Tutorial Project How to put a movie player on your Weebly website using an HTML code.
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction.
Nav Controllers UINavigationController. Overview Nav Controller basics Like a tabview controller, a navViewController manages views A navigationViewController.
Where Value and Innovation Co-exist Gestures and User Interaction Best Practices.
Orientation Configuration adapting to orientation changes.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
Table Views UITableView.
1 UI Alert View iPhone/iPad, iOS Development Tutorial.
Working with the interface and interacting with the iPad app.
Vex Robotics program three: using motors and sensors together.
WebViews UIWebView. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and xib) that manages.
Import existing part with drawing
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Introduction to Apps Development for the iPhone and the Android OS
Java FX: Scene Builder.
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
Dance Cards Dance Cards
Dance Cards Dance Cards
Dance Cards Dance Cards
Dance Cards Dance Cards
CSC 581: Mobile App Development
Dance Cards Dance Cards
Dance Cards Dance Cards
Visual programming Chapter 2: Events and Event Handling
Dance Cards Dance Cards
CSC 581: Mobile App Development
Dance Cards Dance Cards
Using Templates and Library Items
Clemson For iOS Devices and Wi-Fi Setup
Dance Cards Dance Cards
Dance Cards Dance Cards
Dance Cards Dance Cards
EEC-492/693/793 iPhone Application Development
CSC 581: Mobile App Development
CSC 581: Mobile App Development
Dance Cards Dance Cards
UI Elements 2.
Dance Cards Dance Cards
Presentation transcript:

Gestures UIGestureRecognizer

gestures There are 6 default gestures recognized by iOS: Tap gesture (UITapGestureRecognizer) Pan gesture (UIPanGestureRecognizer) Pinch gesture (UIPinchGestureRecognizer) Rotate gesture (UIRotationGestureRecognizer) Swipe gesture (UISwipeGestureRecognizer) Long press gesture (UILongPressGestureRecognizer) You can also make your own gesture recognizers Reference tutorial: http://www.raywenderlich.com/76020/using- uigesturerecognizer-with-swift-tutorial

Process Create an instance of a gesture recognizer Attach the instance to a view Create the gesture handler Can be done programmatically or via IB we’ll do it programmatically

Example Create a new project (can be a single view or a tabbed view) Put a label on the view and connect an IBOutlet to the label Add an imageView from the library. Add an image to your project and assign it to the image view. Add an IBOutlet and connect it to your image. Name the outlet theImage Make sure that User Interaction Enabled is checked in both the identity inspector and the attributes inspector

Pan Gestures This allows you to move a view. In the storyboard, drag a “Pan Gesture Recognizer” from the object library onto the view. Click on the image and then look in the Connections Inspector. Note that the outlet collections now has a connection to the gesture recognizer In the Connections Inspector, drag from the “Pan Gesture Recognizer” in the Document Outline to the “View Controler”

Pan Gestures Add to the ViewController.swift file: translation gives the amount the view has moved relative to the starting point Add to the ViewController.swift file: @IBAction func handlePan(recognizer:UIPanGestureRecognizer) { let translation = recognizer.translationInView(self.view) if let view = recognizer.view { view.center = CGPoint(x:view.center.x + translation.x, y:view.center.y + translation.y) } recognizer.setTranslation(CGPointZero, inView: self.view) Store the new view center in view.center Update the view center to the new center

Run You should be able to move the image.

Tap gesture We will do this one programmatically. Add the variable numTaps and then change viewDidLoad: var numTaps: Int = 0 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let recognizer = UITapGestureRecognizer(target: self, action:Selector("handleTap:")) recognizer.delegate = self theImage.addGestureRecognizer(recognizer) } numTaps keeps track of the number of times the image has been touched recognizer is a constant that refers to the TapGesture We make the tapGesture delegate this viewController Must add the TapGesture recognizer to the image. Note that theImage is the name of our IBOutlet for the image in the storyboard.

ViewController.swift Add this method to ViewController.swift: func handleTap(recognizer: UITapGestureRecognizer) { numTaps++ tapsField.text = String(numTaps) } numTaps keeps track of the number of times the image has been touched Change the label to include the number of taps

run If tapping on the image doesn’t change the label, make sure that you’ve clicked the “User Interaction Enabled” checkbox on the image in the storyboard.

Pinch gesture Drag a “Pinch Gesture Recognizer” from the Object Library to the image. Connect the gesture recognizer to the view controller as you did for the pan gesture. Copy the code below to your ViewController.swift @IBAction func handlePinch(recognizer : UIPinchGestureRecognizer) { if let view = recognizer.view { view.transform = CGAffineTransformScale(view.transform, recognizer.scale, recognizer.scale) recognizer.scale = 1 }

run Should be able to expand/shrink the image