This article shares the specific code for iOS sliding full screen to realize the return function for your reference. The specific content is as follows
The system comes with the sliding return function, which can only be used to slide the edge, and we hope to achieve the return function by sliding the full screen.
Define BaseNavigationController to replace UINavigationController
// #import <UIKit/> @interface BaseNavigationController : UINavigationController @end // #import "" @interface BaseNavigationController () <UIGestureRecognizerDelegate> @end @implementation BaseNavigationController #pragma mark - System method+ (void)load { UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:self, nil]; // As long as it is set through the model, it is set through rich text // Set the navigation bar title => UINavigationBar NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20.0]; [navBar setTitleTextAttributes:attrs]; // Set navigation bar background picture [navBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // Control the return gesture by yourself// = self; // NSLog(@" : %@",); // NSLog(@" : %@",); // Full screen return gesture, not edge return gesture UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget: action:@selector(handleNavigationTransition:)]; [ addGestureRecognizer:pan]; // Control when the gesture is triggered, only non-root controllers need to set off the gesture = self; // Forbid previous gestures = NO; } /** * : <UIScreenEdgePanGestureRecognizer: 0x7fb57dc23510; state = Possible; delaysTouchesBegan = YES; view = <UILayoutContainerView 0x7fb57dc220e0>; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x7fb57dc1c570>)>> * : <_UINavigationInteractiveTransition: 0x7fb57dc1c570> */ #pragma mark - UIGestureRecognizerDelegate - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { // The return gesture will be triggered when it is not the root controller return ( > 1); } #pragma mark - Rewrite- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { if ( > 0) { // means not the root controller // Custom return button overwrites the system's return gesture = [UIBarButtonItem setBackButtonItemWithImage:[UIImage imageNamed:@"navigationButtonReturn"] highlightedImage:[UIImage imageNamed:@"navigationButtonReturnClick"] target:self action:@selector(backClick) title:@"return"]; } [super pushViewController:viewController animated:animated]; } - (void)backClick { [self popViewControllerAnimated:YES]; } @end
UIBarButtonItem+item
// UIBarButtonItem+ #import <UIKit/> @interface UIBarButtonItem (item) + (UIBarButtonItem *)setBarButtonItemWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage target:(id)target action:(SEL)action; + (UIBarButtonItem *)setBarButtonItemWithImage:(UIImage *)image selectedImage:(UIImage *)selectedImage target:(id)target action:(SEL)action; + (UIBarButtonItem *)setBackButtonItemWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage target:(id)target action:(SEL)action title:(NSString *)title; @end // UIBarButtonItem+ #import "UIBarButtonItem+" @implementation UIBarButtonItem (item) + (UIBarButtonItem *)setBarButtonItemWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage target:(id)target action:(SEL)action { // UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom]; [leftButton setImage:image forState:UIControlStateNormal]; [leftButton setImage:highlightedImage forState:UIControlStateHighlighted]; [leftButton sizeToFit]; // Button click event [leftButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; // Since using button will increase the click range, put the button into the view and assign a value UIView *leftView = [[UIView alloc] initWithFrame:]; [leftView addSubview:leftButton]; return [[UIBarButtonItem alloc] initWithCustomView:leftView]; } + (UIBarButtonItem *)setBackButtonItemWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage target:(id)target action:(SEL)action title:(NSString *)title { // Set the return button UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom]; [backButton setTitle:title forState:UIControlStateNormal]; [backButton setImage:image forState:UIControlStateNormal]; [backButton setImage:highlightedImage forState:UIControlStateHighlighted]; [backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [backButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; [backButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; = UIEdgeInsetsMake(0, -15, 0, 0); [backButton sizeToFit]; return [[UIBarButtonItem alloc] initWithCustomView:backButton]; } + (UIBarButtonItem *)setBarButtonItemWithImage:(UIImage *)image selectedImage:(UIImage *)selectedImage target:(id)target action:(SEL)action { // UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom]; [leftButton setImage:image forState:UIControlStateNormal]; [leftButton setImage:selectedImage forState:UIControlStateSelected]; [leftButton sizeToFit]; // Button click event [leftButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; // Since using button will increase the click range, put the button into the view and assign a value UIView *leftView = [[UIView alloc] initWithFrame:]; [leftView addSubview:leftButton]; return [[UIBarButtonItem alloc] initWithCustomView:leftView]; } @end
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.