Custom navigation bar buttons encountered in actual iOS programming, resulting in a workaround for gesture return invalidation

Source: Internet
Author: User
<span id="Label3"></p><p><p>1\ often need to customize the buttons on the navigation bar during the actual programming process, as well As:</p></p><p><p><span style="color: #008000;">-(instancetype) initwithcustomview: (UIView *) customview;</span></p></p><p><p><span style="color: #000000;">however, using this method may cause ios7,8 's gesture to fail, and the workaround is to add the following code to the <span style="color: #339966;">viewdidload</span> method in the custom navigation bar</span></p></p><p><p><span style="color: #ff0000;">Note: The push method can be used only with the system navigation bar, or the navigation bar that inherits from the system, and comes with a return gesture.</span></p></p><pre><pre>-(<span style="color: #0000ff;">void</span><span style="color: #000000;">) viewdidload{ [super viewdidload]; </span> <span style="color: #0000ff;">typeof</span> (self) weakself = self<span style="color: #000000;"> ; </span> <span style="color: #008000;">//</span> <span style="color: #008000;">fixed issue where sliding returned to invalid due to custom navigation bar button</span> <span style="color: #0000ff;">if</span> <span style="color: #000000;">([self respondstoselector: @selector (interactivepopgesturerecognizer)]) { Self.interactivepopgesturerecognizer.</span> <span style="color: #0000ff;">delegate</span> =<span style="color: #000000;"> weakself; }</span> <span style="color: #000000;"> }</span></pre></pre><p><p>Add the above string of code, then run, return gestures can be used normally.</p></p><p><p>2\ also teach you a practical way, when push multiple interface navigation bar <span style="color: #ff0000;">return button</span> , you can override the push method in the custom <span style="color: #339966;">Uinavigationcontroller</span> , intercept the push operation,</p></p><p><p>And also set the Tabbar hidden after push (if necessary), the code is as Follows:</p></p><pre><span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;">* <span style="color: #008000;">* Override this method purpose: ability to intercept all push-in controllers * * @param viewcontroller upcoming push-in Controller</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span>) Pushviewcontroller: (uiviewcontroller *<span style="color: #000000;"><span style="color: #000000;">) Viewcontroller animated: (BOOL) animated{</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(self.viewControllers.count ><span style="color: #800080;"><span style="color: #800080;">0</span></span>) {<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">at this point the push comes in the controller viewcontroller, not the first sub-controller (not the root controller)</span></span> <span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">automatically show and hide Tabbar</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #000000;"><span style="color: #000000;">viewcontroller.hidesbottombarwhenpushed</span></span>=<span style="color: #000000;"><span style="color: #000000;">YES; </span></span><span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">set the contents of the navigation bar above</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: #008000;"><span style="color: #008000;">set the Back button on the left</span></span><span style="color: #000000;"><span style="color: #000000;">ViewController.navigationItem.leftBarButtonItem</span></span>= [uibarbuttonitem itemwithtarget:self action: @selector (back) image:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Home_nav_bar_back_icon</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>Highimage:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Home_nav_bar_back_icon</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: #000000;"><span style="color: #000000;">} [super Pushviewcontroller:viewcontroller animated:animated];}</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) back{</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">because self is a navigation controller, self.navigationcontroller here is Nil.</span></span><span style="color: #000000;"><span style="color: #000000;">[self popviewcontrolleranimated:yes];}</span></span></pre><p><p></p></p><p><p>Custom navigation bar buttons encountered in actual iOS programming, resulting in a workaround for gesture return invalidation</p></p></span>

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.