自定義導航欄返回按鈕導致返回手勢失效問題
需要注意的是手勢代理物件的儲存於轉交問題!!!
UIGestureRecognizerDelegate
自定義無法實現手勢效果圖 Gif
自定義實現手勢效果圖 Gif
ViewController.m
#import "ViewController.h"
#import "NextViewController.h"
@interface ViewController ()
@end
@implementation ViewController
#pragma mark - lifeCycle
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)goToNextVC:(id)sender {
NextViewController *nextVC = [[NextViewController alloc] init];
[self.navigationController pushViewController:nextVC animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
NextViewController.m
#import "NextViewController.h"
@interface NextViewController () <UIGestureRecognizerDelegate>
//變數用來儲存代理:
@property (nonatomic, strong) id<UIGestureRecognizerDelegate> originDelegate;
@end
@implementation NextViewController
- (void)viewDidLoad {
[super viewDidLoad];
//自定義UIBarButtonItem 雖然滿足了 UI 的效果,但是卻導致了左側邊緣滑動失效,得不償失!
UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"imgBack"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemAction)];
self.navigationItem.leftBarButtonItem = leftButtonItem;
//側滑返回互動手勢:UIGestureRecognizer *interactivePopGestureRecognizer
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
//返回上一頁:
- (void)leftBarButtonItemAction {
[self.navigationController popViewControllerAnimated:YES];
}
//檢視已經出現的時候,讓成員變數 originDelegate 儲存 導航控制器的互動返回手勢識別的代理:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.originDelegate = self.navigationController.interactivePopGestureRecognizer.delegate;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
//當檢視將要消失的時候再把剛剛儲存的導航控制器的互動返回手勢識別代理變數重新置為系統自身的!
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.navigationController.interactivePopGestureRecognizer.delegate = self.originDelegate;
self.originDelegate = nil;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
願程式設計讓這個世界更美好
相關文章
- 談導航欄返回按鈕的替代方案
- iOS隱藏導航欄的返回按鈕iOS
- uniapp更改導航欄按鈕文字APP
- uniapp自定義導航欄APP
- iOS開發:給UIWebview的導航欄新增返回、關閉按鈕iOSUIWebView
- iOS 導航條自定義返回按鈕後,怎麼實現右滑返回上一級頁面iOS
- 微信小程式自定義導航欄微信小程式
- ios自定義簡約導航欄iOS
- flutter 自定義tab導航-頂部導航-底部導航Flutter
- HarmonyOS NEXT 5.0自定義增強版導航欄元件|鴻蒙ArkUI自定義標題欄元件鴻蒙UI
- 分析微信(iOS 版)定製導航欄按鈕的思路iOS
- iOS系統導航欄自定義標題動畫跳變解析iOS動畫
- 微信小程式自定義導航欄適配指南微信小程式
- 聊天平臺原始碼,解決設定導航欄按鈕圖片變色問題原始碼
- CSS_導航欄+固定浮動的回到頂部按鈕CSS
- 小程式自定義導航欄適配(完美版)
- 你還在發愁小程式自定義導航欄嗎?
- 關於 Laravel mix 導致 Bootstrap 失效的問題Laravelboot
- [小程式]高適應性的自定義導航欄開發思路
- 一句程式碼恢復自定義leftBarButtonItem導致側滑失效
- 手機直播原始碼,突出底部導航欄中間按鈕的樣式原始碼
- WebMagic多執行緒導致註解失效問題Web執行緒
- android 自定義狀態列和導航欄分析與實現Android
- 線上直播原始碼,自定義導航欄並固定居中對齊原始碼
- 實現全屏返回手勢
- WPF 已知問題 監聽 WMI 事件導致觸控失效事件
- WordPresscategory導航欄Go
- ReactNative導航的右邊新增按鈕做跳轉React
- CARDS主題 & 導航欄樣式修改
- 自定義View:自定義屬性(自定義按鈕實現)View
- 坑爹的導航欄返回鍵(navigationItem.backButtonBarItem)Navigation
- LabVIEW的自定義按鈕View
- GitHub 導航欄加強Github
- HTML橫向導航欄HTML
- Flutter 導航欄AppBarFlutterAPP
- Tablayout實現導航欄TabLayout
- iOS 導航欄的控制iOS
- bootstrap導航欄學習boot