91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

iOS如何滑動全屏實現返回功能

發布時間:2021-09-28 10:11:16 來源:億速云 閱讀:139 作者:小新 欄目:編程語言

這篇文章主要介紹了iOS如何滑動全屏實現返回功能,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

具體內容如下

系統自帶的滑動返回功能,只能滑動邊緣返回,而我們希望通過滑動全屏實現返回功能。

定義BaseNavigationController來取代UINavigationController

// BaseNavigationController.h#import <UIKit/UIKit.h>@interface BaseNavigationController : UINavigationController@end// BaseNavigationController.m#import "BaseNavigationController.h"@interface BaseNavigationController () <UIGestureRecognizerDelegate>@end@implementation BaseNavigationController#pragma mark - 系統方法+ (void)load{ UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:self, nil]; // 只要是通過模型設置,都是通過富文本設置 // 設置導航條標題 => UINavigationBar NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20.0]; [navBar setTitleTextAttributes:attrs]; // 設置導航條背景圖片 [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); // 全屏返回手勢,而不是邊緣返回手勢 UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)]; [self.view addGestureRecognizer:pan]; // 控制手勢什么時候觸發,只有非根控制器才需要出發手勢 pan.delegate = self; // 禁止之前手勢 self.interactivePopGestureRecognizer.enabled = NO;}/** * self.interactivePopGestureRecognizer : <UIScreenEdgePanGestureRecognizer: 0x7fb57dc23510; state = Possible; delaysTouchesBegan = YES; view = <UILayoutContainerView 0x7fb57dc220e0>; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x7fb57dc1c570>)>> * self.interactivePopGestureRecognizer.delegate : <_UINavigationInteractiveTransition: 0x7fb57dc1c570> */#pragma mark - UIGestureRecognizerDelegate- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ // 當不是根控制器時才會觸發返回手勢 return (self.childViewControllers.count > 1);}#pragma mark - 重寫- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{ if (self.childViewControllers.count > 0) { // 代表不是根控制器  // 自定義返回按鈕覆蓋了系統的返回手勢  viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem setBackButtonItemWithImage:[UIImage imageNamed:@"navigationButtonReturn"] highlightedImage:[UIImage imageNamed:@"navigationButtonReturnClick"] target:self action:@selector(backClick) title:@"返回"]; } [super pushViewController:viewController animated:animated];}- (void)backClick{ [self popViewControllerAnimated:YES];}@end

UIBarButtonItem+item

// UIBarButtonItem+item.h#import <UIKit/UIKit.h>@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]; // 按鈕點擊事件 [leftButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; // 由于使用button會使得點擊范圍增大,所以將button放進view中,然后賦值 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{ // 設置返回按鈕 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]; // 按鈕點擊事件 [leftButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; // 由于使用button會使得點擊范圍增大,所以將button放進view中,然后賦值 UIView *leftView = [[UIView alloc] initWithFrame:leftButton.bounds]; [leftView addSubview:leftButton]; return [[UIBarButtonItem alloc] initWithCustomView:leftView];}@end

感謝你能夠認真閱讀完這篇文章,希望小編分享的“iOS如何滑動全屏實現返回功能”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

ios
AI

崇礼县| 昭平县| 塔河县| 同江市| 徐州市| 德令哈市| 龙川县| 常熟市| 萨迦县| 三台县| 阿荣旗| 仁布县| 嘉兴市| 瓮安县| 资讯| 盈江县| 临泽县| 彩票| 阿克| 广河县| 白水县| 邯郸县| 新竹市| 门源| 宁武县| 盘锦市| 五大连池市| 龙南县| 台州市| 化隆| 银川市| 六盘水市| 沂源县| 东丽区| 福泉市| 岱山县| 阿图什市| 加查县| 安义县| 绥化市| 虞城县|