Introduction to iOS development Uitouch Touch API

Source: Internet
Author: User
Tags uikit

1, Uitouch Introduction

    • When the user touches the screen, a Uitouch object is created;
    • The role of Uitouch preserves touch-related information, such as the location, time, and stage of touch;
    • When the Uitouch object is updated from start to finish, it is destroyed at the end.
    • All Uitouch objects are included in the Uievent event object, and the event is distributed by the Hypervisor uiapplication object.

2. Touch Event Call method

//responding to touch events- (void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Nullable uievent *)Event;//call when the finger is pressed- (void) touchesmoved: (Nsset<uitouch *> *) touches withevent: (Nullable uievent *)Event;//call when the finger moves- (void) touchesended: (Nsset<uitouch *> *) touches withevent: (Nullable uievent *)Event;//call when the finger is lifted- (void) touchescancelled: (Nsset<uitouch *> *) touches withevent: (Nullable uievent *)Event;//Cancel (abnormal leave screen, unexpected interruption)- (void) touchesestimatedpropertiesupdated: (Nsset<uitouch *> *) touches Ns_available_ios (9_1);//some information about the touch events generated by Apple Pencil, such as the direction of Pencil, can be delayed on the IPad or IPhone. //The UIKit callback method Touchbegan is immediately generated, and its returned parameter touch contains additional information generated by the Pencil, which is delayed. Therefore, the first callback will give a pre-estimate of additional information, the delay to get the real value will call the Touchesestimatedpropertiesupdated method to update the additional information. 

3. Uitouch Related API

////UITouch.h//UIKit////Copyright (c) 2007-2017 Apple Inc. All rights reserved.//#import<Foundation/Foundation.h>#import<CoreGraphics/CoreGraphics.h>#import<UIKit/UIKitDefines.h>Ns_assume_nonnull_begin@classUIWindow, UIView, Uigesturerecognizer;typedef ns_enum (Nsinteger, uitouchphase) {Uitouchphasebegan, 
    //Start TouchingUitouchphasemoved,//MovingUitouchphasestationary,//StayUitouchphaseended,//EndUitouchphasecancelled,//Cancel};typedef ns_enum (Nsinteger, uiforcetouchcapability) {Uiforcetouchcapabilityunknown=0,//3D Touch Detection failedUiforcetouchcapabilityunavailable =1,//3D Touch is not availableUiforcetouchcapabilityavailable =2         //3D Touch Available};typedef ns_enum (Nsinteger, Uitouchtype) {uitouchtypedirect,//finger and screen direct contactUitouchtypeindirect,//Indirect contact (no direct contact with the screen)Uitouchtypestylus Ns_available_ios (9_1),//Strokes} ns_enum_available_ios (9_0); typedef ns_options (Nsinteger, uitouchproperties) {Uitouchpropertyforce= (1UL<<0),//StrengthUitouchpropertyazimuth = (1UL<<1),//AzimuthUitouchpropertyaltitude = (1UL<<2),//HeightUitouchpropertylocation = (1UL<<3),//location} ns_available_ios (9_1); Ns_class_available_ios (2_0)@interfaceUitouch:nsobject@property (nonatomic,ReadOnly) Nstimeinterval timestamp;//Time@property (Nonatomic,ReadOnly) Uitouchphase phase;//Status@property (Nonatomic,ReadOnly) Nsuinteger Tapcount;//Click Count@property (Nonatomic,ReadOnly) Uitouchtype type Ns_available_ios (9_0);//Contact Type//radius of contact area//error of Contact radius@property (Nonatomic,ReadOnly) cgfloat Majorradius Ns_available_ios (8_0); @property (Nonatomic,ReadOnly) cgfloat majorradiustolerance Ns_available_ios (8_0); @property (Nullable,nonatomic,ReadOnly, strong) UIWindow *window;//Touch Your Window@property (Nullable,nonatomic,ReadOnly, strong) UIView *view;//Touch your view@property (Nullable,nonatomic,ReadOnly, copy) Nsarray <uigesturerecognizer *> *gesturerecognizers Ns_available_ios (3_2);//Touch Gestures-(Cgpoint) Locationinview: (Nullable UIView *) view;//The touch position on the view-(Cgpoint) Previouslocationinview: (Nullable UIView *) view;//record the position of the previous touch point on the view, and view nil is the entire window//now the exact coordinates of the touch//The exact coordinates of the last touch-(Cgpoint) Preciselocationinview: (Nullable UIView *) View Ns_available_ios (9_1);-(Cgpoint) Precisepreviouslocationinview: (Nullable UIView *) View Ns_available_ios (9_1);//Touch Pressure Value@property (Nonatomic,ReadOnly) cgfloat Force Ns_available_ios (9_0);//Maximum touch pressure value@property (Nonatomic,ReadOnly) cgfloat Maximumpossibleforce Ns_available_ios (9_0);//The azimuth of the positive direction of the x-axis, which is 0 when the positive orientation of the x-axis is the same, and when the view parameter is nil, the Keywindow returns the azimuth (radians) of the stylus. -(CGFloat) Azimuthangleinview: (Nullable UIView *) View Ns_available_ios (9_1);//unit vector in the direction of the current touch object when the view parameter is nil, the default is Keywindow returns the unit vector that points in the direction of the stylus's azimuth. -(Cgvector) Azimuthunitvectorinview: (Nullable UIView *) View Ns_available_ios (9_1);//When the pen is parallel to the plane, the value is 0//When the pen is perpendicular to the plane, the value is PI/2//the height of the stylus (in radians). @property (Nonatomic,ReadOnly) cgfloat altitudeangle Ns_available_ios (9_1);//when the touch characteristics of each touch object change, the value will be incremented separately, and the return value is the NSNumber index number, which allows you to correlate the contact with the original touch update@property (Nonatomic,ReadOnly) NSNumber *_nullable estimationupdateindex Ns_available_ios (9_1);//The current Touch object estimates the Touch property, the return value is uitouchpropertyies a set of touch properties, and these properties are updated. @property (Nonatomic,ReadOnly) uitouchproperties estimatedproperties Ns_available_ios (9_1);//a set of touch performance expectations in future update messages. @property (Nonatomic,ReadOnly) uitouchproperties estimatedpropertiesexpectingupdates Ns_available_ios (9_1);@endNs_assume_nonnull_end
Uitouch related APIs

4. Other

4.1. Type: direct contact, space-separated, strokes;

typedef ns_enum (Nsinteger, Uitouchtype) {    uitouchtypedirect,                       //  finger and screen direct contact    Uitouchtypeindirect,                     //  indirect contact (not directly touching the screen)    //  stroke } ns_enum_ Available_ios (9_0);

4.2. Multi-touch: Rewrite ismultipletouchenabled return to Yes

- (BOOL) ismultipletouchenabled{    return  YES;

4.3. Multiple buttons on the view are triggered individually

- (BOOL) isexclusivetouch{    return  YES;

4.4. When setting ismultipletouchenabled and Isexclusivetouch at the same time, Isexclusivetouch is invalid.

5. Easy to use

5.1. Get a Uitouch object

-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *)event{    * Touch = [touches anyobject];}

5.2. Open multi-touch get touches collection

-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *)event{     // get all the touch objects    Nsarray * array = [touches allobjects];}

Introduction to iOS development Uitouch Touch API

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.