2015-10-31 gestures in IOS

Source: Internet
Author: User

The vast majority of controls in the Uikit framework are inherited from, uiresponder classes, and the Uiresponder class has the powerful ability to handle touch events. If a uiview receives a touch event, then this touch event will go to find the corresponding response event, if it is not found in the UIView, look for UIView object to deal with, if the UIView object does not have the right to handle, Go to the current layer of Uiviewcontroller to find, if you can not find and then look for Uiviewcontroller object to deal with, if this object still can not handle, and then go to the upper UIWindow object to deal with, if it is hot does not solve the response of touch events, Then the touch event is passed to the UIApplication proxy object, and if the proxy object still cannot be resolved, it is handed over to the system for recycling.

Sum up: the equivalent of one thing in the village, the village chief can not decide, then the first level of reporting, but has not been dealt with until the end of a great power of the decision of the people, it is counted. or just keep reporting.

The system encapsulates the event into the Uievent class and is then processed by the system. iOS divides events into three types : Touch events, action events, external control events. Action event: Is the user to the mobile phone to do a specific action, such as shaking; external control events: is the control of the mobile phone connected to the device when the event; Touch event: Is the user and the phone screen related events.

Each user interaction object Uiresponder has a set of response event functions. Usually we have to rewrite this set of functions. For us to use the appropriate logic.

About the concept of knowledge here is no longer talk about blog URL (http://blog.csdn.net/yitailong/article/details/8228946)

Basic code implementation: print out the mouse gesture event

Build a UIView file named TouchView in the view controller to write

#import"RootViewController.h"#import"TouchView.h"@interface Rootviewcontroller () @end @implementation Rootviewcontroller- (void) viewdidload {[Super viewdidload]; [Self Settouchview];}-(void) settouchview{TouchView* TouchView = [[TouchView alloc]initwithframe:cgrectmake ( -, -, -, -)]; Touchview.backgroundcolor=[Uicolor Redcolor];        [Self.view Addsubview:touchview]; UIButton* Button =[UIButton Buttonwithtype:uibuttontypecustom]; Button.frame= CGRectMake ( -, $,280, -); Button.backgroundcolor=[Uicolor Graycolor];    [Button addtarget:self Action: @selector (buttonaction:) forcontrolevents:uicontroleventtouchupinside]; [Button settitle:@"Click to jump"Forstate:uicontrolstatenormal];        [Self.view Addsubview:button]; Pinchview* View = [[Pinchview alloc]initwithframe:cgrectmake ( -, -, -, -)]; View.backgroundcolor=[Uicolor Blackcolor];        [Self.view Addsubview:view]; }-(void) Buttonaction: (UIButton *) sender{Secondviewcontroller* SVC =[[Secondviewcontroller alloc]init]; [Self.navigationcontroller pushviewcontroller:svc animated:yes];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}
View Code

Write it in the uiview.m file.

#import"TouchView.h"@implementation TouchView-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event{[self updateinfor:[touches anyobject] Withmethodname:@"Touchesbegin"];}-(void) touchescancelled: (Nsset *) touches withevent: (Uievent *)Event{[self updateinfor:[touches anyobject] Withmethodname:@"touchescancelled"];}-(void) touchesended: (Nsset *) touches withevent: (Uievent *)Event{[self updateinfor:[touches anyobject] Withmethodname:@"touchesended"];}-(void) touchesmoved: (Nsset *) touches withevent: (Uievent *)Event{[self updateinfor:[touches anyobject] Withmethodname:@"touchesmoved"];}-(void) Updateinfor: (Uitouch *) Atouch withmethodname: (NSString *) amethodname{NSString* Strphase =@""; Switch(atouch.phase) { CaseUitouchphasebegan:strphase=@"Uitouchphasebegan";  Break;  CaseUitouchphaseended:strphase=@"uitouchphaseended";  Break;  CaseUitouchphasecancelled:strphase=@"uitouchphasecancelled";  Break;  CaseUitouchphasemoved:strphase=@"uitouchphasemoved";  Break; default:             Break; } NSLog (@"The action event is%@", strphase);} @end
View Code

2015-10-31 gestures in IOS

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.