IOS app slide back to right, iOS app slide back
Prerequisites: There are two pages, A and B. A is the main interface and A is pushed to B.
Method 1: If the return button of page B needs a Custom button (in iOS7, if UINavigationController is used, the system attaches a pop gesture that slides from the left edge of the screen. However, if you customize the leftBarButtonItem of navigationItem, this gesture will become invalid .)
On interface:
-(Void) viewDidAppear :( BOOL) animated {
Self. navigationController. interactivepopgsturerecognizer. delegate = (id) self; // reset the proxy
Self. navigationController. interactivepopgsturerecognizer. enabled = NO; // This page cannot be right-slide
}
In B:
Set the return button:
UIButton * backBtn = [UIButton buttonWithType: UIButtonTypeCustom];
BackBtn. frame = CGRectMake (5, 2, 21, 35 );
[BackBtn setImage: [UIImage imageNamed: @ "back"] forState: UIControlStateNormal];
[[BackBtn rac_signalForControlEvents: UIControlEventTouchUpInside] subscribeNext: ^ (id x ){
[Self. navigationController popViewControllerAnimated: YES];
}];
UIBarButtonItem * backItem = [[UIBarButtonItem alloc] initWithCustomView: backBtn];
Self. navigationItem. leftBarButtonItem = backItem;
Self. navigationController. interactivepopgsturerecognizer. enabled = YES; // The Most Important Step
Method 2: In page A (the backBarButtonItem in page A is actually the return button of page B we see. The leftBar in page B is the button on the left. Pay attention to the priority, there is A custom leftBar in B, which is displayed on page B. If not, check the page A. If there is backBarButtonItem in it, it is displayed. If not, it is the default one in the system)
UIImage * image = [UIImage imageNamed: @ "back"];
UIBarButtonItem * item = [[UIBarButtonItem alloc] init];
[Item setBackButtonBackgroundImage: [image resizableImageWithCapInsets: UIEdgeInsetsMake (0, image. size. width, 0, 0)] forState: UIControlStateNormal barMetrics: UIBarMetricsDefault];
[Item setBackButtonTitlePositionAdjustment: UIOffsetMake (-400.f, 0) forBarMetrics: UIBarMetricsDefault];
Self. navigationItem. backBarButtonItem = item;
Self. navigationItem. backBarButtonItem = item;
I am using method 1 and method 2. I cannot adjust the position of the return button.