iOS Gesture Recognition-click

Source: Internet
Author: User

//
Mjviewcontroller.m
07-Tapping (TAP)
//
Created by Apple on 14-4-20.
Copyright (c) 2014 itcast. All rights reserved.
//

#import "MJViewController.h"

@interface Mjviewcontroller () <UIGestureRecognizerDelegate>
@property (Weak, nonatomic) Iboutlet Uiimageview *iconview;

@end

@implementation Mjviewcontroller

-(void) viewdidload
{
[Super Viewdidload];

[Self TESTTAP2];
}

-(void) TESTTAP2
{
Uigesturerecognizer *tap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Tapview)];
Tap.delegate = self;
[Self.iconview Addgesturerecognizer:tap];
}

#pragma mark-Proxy method
/**
* When clicking on the view, this method is called first
*/
-(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldreceivetouch: (Uitouch *) touch
{
Cgpoint pos = [Touch LocationInView:touch.view];
if (pos.x <= self.iconView.frame.size.width * 0.5) {
return YES;
}
return NO;
}

-(void) Testtap
{
1. Create a gesture Recognizer object
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
2 consecutive strokes to identify success
tap.numberoftapsrequired = 2;
tap.numberoftouchesrequired = 2;

2. Add a gesture Recognizer object to the corresponding view
[Self.iconview Addgesturerecognizer:tap];

3. Add a listening method (identify the corresponding cleaning, will invoke the Listener method)
[Tap addtarget:self Action: @selector (Tapview)];
}

-(void) Tapview
{
NSLog (@ "-----tapview");
}

@end

iOS Gesture Recognition-click

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.