iOS development--run-time OC Post & Use runtime to get system properties: use your own gestures to modify the System's own gestures

Source: Internet
Author: User
<span id="Label3"></p><p style="text-align: center;"><p style="text-align: center;"><span style="font-size: 18pt;">Use the runtime to get the properties of the system: use your own gestures to modify the System's own gestures</span></p></p><p><p></p></p><p><p>Sometimes I need to implement a function, but did not think of a good way or think of the method is just the way to implement it too cumbersome, one or indeed to install force, we will think of iOS development of the best technology runtime (runtime)</p></p><p><p>About the runtime here is not much to say, please check the author moved over a selection of articles, here is mainly how to use the runtime in the actual development of the function we want to Achieve.</p></p><p><p></p></p><p><p>For example, in the development of iOS has such a problem, about the navigation bar we click a button will jump to the corresponding sub-controller, but here is the problem, we can click on the corresponding Word controller in the corresponding back button to achieve return, but if the user is using sliding, here will be a problem, But what's the problem?</p></p><p><p></p></p><p><p>the <span style="color: #ff6600;">problem is:</span> The user can only in the corresponding sub-controller in the leftmost slide back, the text generally we are all to achieve the global interface sliding can be, so here I want to solve this is the Problem.</p></p><p><p></p></p><p><p><span style="color: #ff0000; font-size: 14pt;">The idea here Is:</span></p></p><p><p>To modify the System's own gesture sliding method, I have to implement, and add some corresponding functions.</p></p><p><p></p></p><p><p>okay, Here's A look at how to use this Technique.</p></p><p><p></p></p><p><p><span style="color: #0000ff;">One: First we need to import the runtime library</span></p></p><p><p><span style="line-height: 1.5;"> </span></p></p><p><p><span style="color: #0000ff;">Second: then use the runtime to print the System's corresponding member properties</span></p></p><p><p></p></p><p><p>Gets the member variable, knows the property name,</p></p><p><p>How to get the property value by the Run-time mechanism, first get the name of the property, get the value by KVC</p></p><p><p>To get target, you need to use the run-time mechanism to iterate through all the property names within the class.</p></p><p><p>Using the runtime to get the property name, you can only get all the property names under the current class, and you cannot get its subclasses or parent Classes.</p></p><p><p>Copyivarlist: get a list of member properties</p></p><p><p>Class: gets the property under which class</p></p><p><p>Outcount: How many member properties are in this class, and the total number of member properties</p></p><p><p></p></p><p><p></p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">*</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #008000;"><span style="color: #008000;">* Print Properties</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #008080;"><span style="color: #008080;">7</span></span>Unsigned<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span>Count =<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">;</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #008080;"><span style="color: #008080;">9</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">get all the member properties in Uigesturerecognizer</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span> <span style="color: #008080;"><span style="color: #008080;"></span> one</span>Ivar *ivars = class_copyivarlist ([uigesturerecognizer<span style="color: #0000ff;"><span style="color: #0000ff;">class</span></span>], &<span style="color: #000000;"><span style="color: #000000;">count);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span>(<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span>i =<span style="color: #800080;"><span style="color: #800080;">0</span></span>; I < count; i++<span style="color: #000000;"><span style="color: #000000;">) {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Get member Properties</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span>Ivar Ivar =<span style="color: #000000;"><span style="color: #000000;">ivars[i];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> at</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">gets the property name of the member property</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span>NSString *name =<span style="color: #000000;"><span style="color: #000000;">@ (ivar_getname (ivar));</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> in</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">NSLog (@ "%@", name);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> to</span>}</pre><p><p></p></p><p><p><span style="color: #0000ff;">Three: because we need to change the dead system corresponding to the gesture, so here need to analyze the system gesture method and corresponding properties, and replace him</span></p></p> <ol> <ol> <li><span style="line-height: 1.5;">when the System's swipe gesture is triggered, the target action is invoked to do the swipe-back thing (action),</span></li> <li><span style="line-height: 1.5;">Gets the target and action returned by the system slide</span></li> </ol> </ol><p><p><span style="line-height: 1.5;">Action:=> handlenavigationtransition:</span></p></p><p><p>Uiscreenedgepangesturerecognizer *gesture = self.interactivepopgesturerecognizer;</p></p><p><p></p></p><p><p><span style="color: #0000ff;">four: from the above Run-time method print out the properties we can know, the system corresponding gesture method value is _targets, so we can use KVC way to get rid of Him. </span></p></p><p><p></p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span>Nsarray *targets = [gesture valueforkeypath:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">_targets</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">];</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">ID</span></span>Gesturerecognizer = targets[<span style="color: #800080;"><span style="color: #800080;">0</span></span><span style="color: #000000;"><span style="color: #000000;">];</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #008080;"><span style="color: #008080;">9</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">ID</span></span>target = [gesturerecognizer valueforkeypath:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">_target</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">];</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span> <span style="color: #008080;"><span style="color: #008080;"></span> one</span> <span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">NSLog (@ "%@", target);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span>self.interactivePopGestureRecognizer.enabled =<span style="color: #000000;"><span style="color: #000000;">NO;</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;">the <span style="color: #008000;">ability to borrow a System's swipe gesture, which invokes the System's sliding back function when it triggers its own swipe gesture</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> at</span>Uipangesturerecognizer *pan =<span style="color: #000000;"><span style="color: #000000;">[[uipangesturerecognizer alloc] initwithtarget:target action: @selector (handlenavigationtransition:)];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span>Pan.<span style="color: #0000ff;"><span style="color: #0000ff;">Delegate</span></span>=<span style="color: #000000;">self <span style="color: #000000;">;</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> in</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> to</span> <span style="color: #000000;"><span style="color: #000000;">[self.view addgesturerecognizer:pan];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> </pre><p><p></p></p><p><p>iOS development--run-time OC Post & Use runtime to get system properties: use your own gestures to modify the System's own gestures</p></p></span>
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.