Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

7. Implementing Gesture Recognizers > 7.4. Detecting Long Press Gestures

7.4. Detecting Long Press Gestures

Problem

You want to be able to detect when the user taps and holds his finger on a view for a certain period of time.

Solution

Create an instance of the UILongPressGestureRecognizer class and add it to the view that has to detect long tap gestures. The .h file of the view controller is defined in this way:

#import <UIKit/UIKit.h>

@interface Detecting_Long_Press_GesturesViewController : UIViewController

@property (nonatomic, strong)
  UILongPressGestureRecognizer *longPressGestureRecognizer;

@property (nonatomic, strong) UIButton *dummyButton;

@end

Here is the viewDidLoad instance method of the view controller that uses the long press gesture recognizer that we defined in the .m file:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint