The IOS intercepts control events and continues the original message passing process after processing.

Source: Internet
Author: User

# Import
<Objc/objc. h>

# Import <objc/runtime. h>

-(Void) sendeventhooked :( uievent *) event {

// Do what you want to do here

Nslog (@ "interception event: % @",
[Eventdescription]);

// Execute the original message passing process

[Selfperformselector: @ selector (sendeventoriginal :) withobject: event];

}

-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary
*) Launchoptions

{

Method sendevent = class_getinstancemethod ([uiwindowclass], @ selector (sendevent :));

Method sendeventmyself = class_getinstancemethod ([selfclass],
@ Selector (sendeventhooked :));

IMP sendevenibd = method_getimplementation (sendevent );

Class_addmethod ([uiwindowclass], @ selector (sendeventoriginal :),
Sendevenibd, method_gettypeencoding (sendevent ));

IMP sendeventmyselfimp = method_getimplementation (sendeventmyself );

Class_replacemethod ([uiwindowclass], @ selector (sendevent :),
Sendeventmyselfimp, method_gettypeencoding (sendevent ));

Self. Window = [[[uiappswalloc] initwithframe: [[uiscreenmainscreen] bounds] autorelease];

// Override point for customization after application launch.

If ([[uidevicecurrentdevice] userinterfaceidiom]
= Uiuserinterfaceidiomphone ){

Self. viewcontroller = [[[viewcontrolleralloc] initwithnibname: @ "viewcontroller_iphone" Bundle: Nil] autorelease];

} Else {

Self. viewcontroller = [[[viewcontrolleralloc] initwithnibname: @ "viewcontroller_ipad" Bundle: Nil] autorelease];

}

Self. Window. rootviewcontroller = self. viewcontroller;

[Self. windowmakekeyandvisible];

Return yes;

}

Then you can create a button elsewhere to capture the button touch event!

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.