In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces iOS how to slide full screen to achieve the return function, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
The details are as follows
The system comes with the sliding return function, which can only slide the edge, but we hope to achieve the return function by sliding the full screen.
Define BaseNavigationController to replace UINavigationController
/ / BaseNavigationController.h#import @ interface BaseNavigationController: UINavigationController@end// BaseNavigationController.m#import "BaseNavigationController.h" @ interface BaseNavigationController () @ end@implementation BaseNavigationController#pragma mark-system method + (void) load {UINavigationBar * navBar = [UINavigationBar appearanceWhenContainedIn:self, nil]; / / whenever it is set through the model, the navigation bar title is set through rich text = > UINavigationBar NSMutableDictionary * attrs = [NSMutableDictionary dictionary]; attrs [NSFontAttributeName] = [UIFont boldSystemFontOfSize:20.0]; [navBar setTitleTextAttributes:attrs] / / set the navigation bar background image [navBar setBackgroundImage: [UIImage imageNamed:@ "navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];}-(void) viewDidLoad {[super viewDidLoad]; / / Do any additional setup after loading the view. / / self.interactivePopGestureRecognizer.delegate = self;// NSLog (@ "self.interactivePopGestureRecognizer:% @", self.interactivePopGestureRecognizer); / / NSLog (@ "self.interactivePopGestureRecognizer.delegate:% @", self.interactivePopGestureRecognizer.delegate); / / full screen return gesture instead of edge return gesture UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector (handleNavigationTransition:)]; [self.view addGestureRecognizer:pan] / / controls when the gesture is triggered. Only the non-root controller needs to start the gesture pan.delegate = self; / / disable the previous gesture self.interactivePopGestureRecognizer.enabled = NO;} / * self.interactivePopGestureRecognizer: * self.interactivePopGestureRecognizer.delegate: * / # pragma mark-UIGestureRecognizerDelegate- (BOOL) gestureRecognizer: (UIGestureRecognizer *) gestureRecognizer shouldReceiveTouch: (UITouch *) touch {/ / the return gesture return (self.childViewControllers.count > 1) is triggered when it is not the root controller. } # pragma mark-rewrite-(void) pushViewController: (UIViewController *) viewController animated: (BOOL) animated {if (self.childViewControllers.count > 0) {/ / indicates that it is not the root controller / / the custom return button overrides the system's return gesture viewController.navigationItem.leftBarButtonItem = [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+item.h#import @ 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+item.m#import "UIBarButtonItem+item.h" @ implementation UIBarButtonItem (item) + (UIBarButtonItem *) setBarButtonItemWithImage: (UIImage *) image highlightedImage: (UIImage *) highlightedImage target: (id) target action: (SEL) action {/ / 1.leftBarButtonItem 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] / / because using button increases the click range, put button into view and assign UIView * leftView = [[UIView alloc] initWithFrame:leftButton.bounds]; [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]; backButton.contentEdgeInsets = 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 {/ / 1.leftBarButtonItem 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] / / because using button will increase the click range, put button into view and assign UIView * leftView = [[UIView alloc] initWithFrame:leftButton.bounds]; [leftView addSubview:leftButton]; return [[UIBarButtonItem alloc] initWithCustomView:leftView];} @ end
Thank you for reading this article carefully. I hope the article "how to swipe iOS to achieve full screen return function" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.