UIView drag and a little explanation of Uiresponder and Uitouch

Source: Internet
Author: User

UIView drag and Drop1. Customizing a UIView2. Implementing the Touchmoved method in the UIView. m fileThe implementation code is as follows#import "Kds.h"

@implementation KDS

-(void) touchesmoved: (Nsset<uitouch *> *) touches withevent: (uievent *) event{
Uitouch *touch = [touches anyobject];
//Get current point
cgpoint curp = [Touch locationinview:self];
//Get previous point
cgpoint PreP = [Touch previouslocationinview:self];
//Get x-axis offset
cgfloat OffsetX = curp.x-prep.x;
//Modify the view's location (frame, center, transform)
    
//self.transform = cgaffinetransformmaketranslation (OffsetX, 0);

//Gets the offset of the y-axis
cgfloat OffsetY = curp.y-prep.y;
    
self.transform = cgaffinetransformtranslate (Self.transform, OffsetX, OffsetY);} Additional notes :events in iOS can be divided into 3 major types1. Touch Event 2. Accelerometer Event 3. Remote Control Eventnot all objects in iOS can handle events, only objects that inherit Uiresponder can accept and handle events. We call it "responder object."Uiapplication/uiviewcontroller/uiview are inherited from Uiresponder, so they are all responder objects that are able to receive and handle events Uiresponder internally provides the following methods to handle events 1. Touch events:Touchesbegan, touchesmoved, touchesended, touchescancelled 2. Accelerometer event:motionbegan/motionended/motioncancelled 3. Remote Control event:remotecontrolreceivedwithevent Uitouchwhen the user touches the screen with one finger, a Uitouch object associated with the finger is createdOne finger corresponds to a Uitouch objectthe role of Uitouchholds information about the finger, such as the location of the touch, the event, the stageWhen the finger moves, the system updates the same Uitouch object so that it can keep the finger in the touch positionwhen the finger leaves the screen, the system destroys the corresponding Uitouch objectproperties of the Uitouch1. Touch the window where it was generated UIWindow2. The attempt to UIView when the touch is generated3. The number of times you tap the screen in a short time Nsinteger tapcount4. Record the time when the touch event was generated or changed, in seconds Nstimeinterval5. The status of the current touch event UitouchphaseMethods of Uitouch1.locationInViewThe return value indicates the position of the touch on the viewThe position returned here is for the view's coordinate system (as the origin (0.0) in the upper-left corner of the view) when the incoming parameter is nil, the position of the touch point in UIWindow is returned .2.previousLocaitonInViewThis method records the position of the previous touch point uieventeach occurrence of an event produces a Uievent objectuievent: Called an event object to record the time and type of event generationCommon Properties1. Event TypeUieventtypeUieventsubtype2. Time the event was generatedNstimeintervalUievent also provides a way to get a touch object on a view (Uitouch)   

UIView drag and a little explanation of Uiresponder and Uitouch

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.