iOS Touch-screen event guide

Source: Internet
Author: User
Tags touch

This article mainly gives you a summary of 2 ways to implement the iOS touch-screen event, simple and practical, the need for small partners can refer to.

The code is as follows:

Inside a function (initialization, etc.), add the scope to identify the touch event

Infoview=[[uiview Alloc] Initwithframe:cgrectmake (20, 100,220, 280)];//range, out of this range will not detect the touch of

Infoview.backgroundcolor=[uicolor Bluecolor];

infoview.alpha=0.6;

[Self.view Addsubview:infoview];

/****************** surveillance gesture control *****************///have up and down, I only used to the left and right, up and down.

Uiswipegesturerecognizer *recognizer;

recognizer = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (Handleswipefrom:)];

[Recognizer Setdirection: (uiswipegesturerecognizerdirectionright)];

[InfoView Addgesturerecognizer:recognizer];

recognizer = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (Handleswipefrom:)];

[Recognizer Setdirection: (Uiswipegesturerecognizerdirectionup)];

[Self.view Addgesturerecognizer:recognizer];

recognizer = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (Handleswipefrom:)];

[Recognizer Setdirection: (Uiswipegesturerecognizerdirectiondown)];

[Self.view Addgesturerecognizer:recognizer];

recognizer = [[Uiswipegesturerecognizer alloc] initwithtarget:self action: @selector (Handleswipefrom:)];

[Recognizer Setdirection: (Uiswipegesturerecognizerdirectionleft)];

[InfoView Addgesturerecognizer:recognizer];

realization function of touch event

Sliding Event 1

-(void) Handleswipefrom: (Uiswipegesturerecognizer *) recognizer{

If you slide to the left,

if (recognizer.direction==uiswipegesturerecognizerdirectionleft) {

NSLog (@ "**************** slide **************** to the left");

}

If you slide right

if (recognizer.direction==uiswipegesturerecognizerdirectionright) {

NSLog (@ "**************** right sliding ****************");

}

if (Recognizer.direction==uiswipegesturerecognizerdirectiondown) {

NSLog (@ "**************** to slide ****************");

}

if (recognizer.direction==uiswipegesturerecognizerdirectionup) {

NSLog (@ "**************** upward sliding ****************");

}

}

Method Two:

The code is as follows:

Gseventrecord header;

Gshardwarekeyinfo key = {0,0,0,0,1,{' a '},1,{' a '},0,0,0,0};

memset (&header, 0, sizeof (header));

Header.type = Kgseventkeydown;

header.infosize = sizeof (Gshardwarekeyinfo);

Header.timestamp = Mach_absolute_time ();

struct

{

Gseventrecord Header1;

Gshardwarekeyinfo Key1;

}fuck = {header, key};

Gssendevent (&fuck, Gsgetpurpleapplicationport ());

Gseventrecord header;

Gshardwarekeyinfo key = {0,0,0,0,1,{' a '},1,{' a '},0,0,0,0};

memset (&header, 0, sizeof (header));

Header.type = Kgseventkeydown;

header.infosize = sizeof (Gshardwarekeyinfo);

Header.timestamp = Mach_absolute_time ();

struct

{

Gseventrecord Header1;

Gshardwarekeyinfo Key1;

}fuck = {header, key};

Gssendevent (&fuck, Gsgetpurpleapplicationport ());

The above mentioned is the entire content of this article, I hope you can enjoy.

Related Article

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.