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

溫馨提示×

溫馨提示×

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

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

iOS滑動全屏實現返回功能

發布時間:2020-10-13 20:38:31 來源:腳本之家 閱讀:200 作者:抬頭看見檸檬樹 欄目:移動開發

本文實例為大家分享了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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

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

AI

肥城市| 息烽县| 五寨县| 五大连池市| 屏东市| 湾仔区| 志丹县| 岑溪市| 阳谷县| 喀什市| 桂平市| 南汇区| 乡城县| 蛟河市| 雷波县| 青龙| 张家港市| 汽车| 沈阳市| 屏山县| 灌南县| 开平市| 文化| 晋中市| 黄梅县| 田东县| 犍为县| 巴青县| 布拖县| 万州区| 灵川县| 习水县| 浠水县| 芦溪县| 乌拉特中旗| 永新县| 上高县| 浮山县| 大足县| 南开区| 平昌县|