IOS Custom Back button to keep the system sliding back

Source: Internet
Author: User

1. Introduction

Using the iphone, the favorite is to use its sliding back. As a developer, when we write a lot of pages, there is always a reason why the system's sliding back is not available. Use the navigation bar to push out a controller, We have customized a return button in the controller. This way the system defaults to the swipe back gesture effect is gone.

2. Workaround

[1] From a This controller push to b this controller, we want to customize the B's Return button, we can set in a

Self.navigationItem.backBarButtonItem = [[Uibarbuttonitem alloc] initwithtitle:@ "Wang Yu" style: Uibarbuttonitemstyleplain Target:nil Action:nil];

[2] in the B Controller set back button, I think this should be the choice most people like, but when we set in the B controller, we self.navigationItem.leftBarButtonItem found that the system's sliding return gesture failed. So how can you keep the system sliding back gesture, we can do this in the B controller.

@interface  ViewController  ()  @[email protected] ViewController-  (void) viewdidload {        [super viewdidload];         //  Custom return button         uibutton * Button = [[uibutton alloc]initwithframe:cgrectmake (0, 0, 44, 44)];         [button settitle:@ "Wang Yu 2"  forState:UIControlStateNormal];         [button settitlecolor:[uicolor blackcolor] forstate: Uicontrolstatenormal];        [button addtarget:self action: @selector (back:)  forControlEvents:UIControlEventTouchUpInside];         self.navigationitem.leftbarbuttonitem = [[uibarbuttonitem alloc]initwithcustomview:button ];} -  (void) Back: (Uibutton *) button {        [self.navigationcontroller  Popviewcontrolleranimated:yes];} -  (void) Viewwillappear: (BOOL) animated {    [super viewwillappear:animated];     if  (self.navigationcontroller.viewcontrollers.count > 1)  {           //  Record system returns proxy for gesture          _delegate = self.navigationController.interactivePopGestureRecognizer.delegate;           //  set the system return gesture proxy for the current controller          self.navigationController.interactivePopGestureRecognizer.delegate = self;     }}-  (void) Viewwilldisappear: (BOOL) Animated {    [super  viewWillDisappear:animated];     //  set the system return gesture agent for the system we just entered the controller to record the return gesture agent &NBSp;   self.navigationcontroller.interactivepopgesturerecognizer.delegate = _delegate;} #pragma  mark - UIGestureRecognizerDelegate-  (BOOL) Gesturerecognizershouldbegin: ( uigesturerecognizer *) Gesturerecognizer {        return  self.navigationcontroller.childviewcontrollers.count > 1;} -  (BOOL) Gesturerecognizer: (uigesturerecognizer *) gesturerecognizer  Shouldrecognizesimultaneouslywithgesturerecognizer: (uigesturerecognizer *) otherGestureRecognizer {     return self.navigationcontroller.viewcontrollers.count > 1;} @end

IOS Custom Back button, leave the system sliding back

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.