chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// TLViewController.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/1/23.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "UIViewController+PopGesture.h"
|
||||
|
||||
@interface TLViewController : UIViewController
|
||||
|
||||
@property (nonatomic, strong) NSString *analyzeTitle;
|
||||
|
||||
/// 当前VC stutusBar的状态,仅在viewWillAppear时生效,默认LightContent
|
||||
@property (nonatomic, assign) UIStatusBarStyle statusBarStyle;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// TLViewController.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/1/23.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLViewController.h"
|
||||
|
||||
@implementation TLViewController
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
[self setStatusBarStyle:UIStatusBarStyleLightContent];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
[self.view setBackgroundColor:[UIColor colorGrayBG]];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
[MobClick beginLogPageView:self.analyzeTitle];
|
||||
if ([UIApplication sharedApplication].statusBarStyle != self.statusBarStyle) {
|
||||
[UIApplication sharedApplication].statusBarStyle = self.statusBarStyle;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewWillDisappear:animated];
|
||||
[MobClick endLogPageView:self.analyzeTitle];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
#ifdef DEBUG_MEMERY
|
||||
NSLog(@"dealloc %@", self.navigationItem.title);
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma mark - # Getter
|
||||
- (NSString *)analyzeTitle
|
||||
{
|
||||
if (_analyzeTitle == nil) {
|
||||
return self.navigationItem.title;
|
||||
}
|
||||
return _analyzeTitle;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// UIViewController+PopGesture.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 2017/9/26.
|
||||
// Copyright © 2017年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface UIViewController (PopGesture) <UIGestureRecognizerDelegate>
|
||||
|
||||
/// 禁用手势返回(默认为NO)
|
||||
@property (nonatomic, assign) BOOL disablePopGesture;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// UIViewController+PopGesture.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 2017/9/26.
|
||||
// Copyright © 2017年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UIViewController+PopGesture.h"
|
||||
|
||||
#pragma mark - ## UINavigationController (TLViewController)
|
||||
|
||||
@interface UINavigationController (TLViewController)
|
||||
|
||||
@property (nonatomic, strong, readonly) id systemInteractivePopGestureRecognizerDelegate;
|
||||
|
||||
@end
|
||||
|
||||
@implementation UINavigationController (TLViewController)
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
TLExchangeMethod(@selector(initWithRootViewController:), @selector(__tt_initWithRootViewController:))
|
||||
}
|
||||
|
||||
- (id)__tt_initWithRootViewController:(UIViewController *)rootViewController
|
||||
{
|
||||
[self __tt_initWithRootViewController:rootViewController];
|
||||
[self setAssociatedObject:self.interactivePopGestureRecognizer.delegate forKey:@"systemInteractivePopGestureRecognizerDelegate" association:TLAssociationStrong];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)systemInteractivePopGestureRecognizerDelegate
|
||||
{
|
||||
return [self associatedObjectForKey:@"systemInteractivePopGestureRecognizerDelegate"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation UIViewController (PopGesture)
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
TLExchangeMethod(@selector(viewWillAppear:), @selector(__tt_viewWillAppear:))
|
||||
}
|
||||
|
||||
- (void)__tt_viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[self __tt_viewWillAppear:animated];
|
||||
|
||||
if ([self.navigationController.childViewControllers containsObject:self]) {
|
||||
if (self.disablePopGesture) {
|
||||
if ([self.navigationController respondsToSelector:@selector(systemInteractivePopGestureRecognizerDelegate)]) {
|
||||
self.navigationController.interactivePopGestureRecognizer.delegate = self;
|
||||
}
|
||||
else {
|
||||
NSLog(@"不能禁用右滑手势");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ([self.navigationController respondsToSelector:@selector(systemInteractivePopGestureRecognizerDelegate)]) {
|
||||
id delegate = [self.navigationController valueForKey:@"systemInteractivePopGestureRecognizerDelegate"];
|
||||
if (delegate && self.navigationController.interactivePopGestureRecognizer.delegate != delegate) {
|
||||
self.navigationController.interactivePopGestureRecognizer.delegate = delegate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - # Public Methods
|
||||
- (void)setDisablePopGesture:(BOOL)disablePopGesture
|
||||
{
|
||||
[self setAssociatedObject:@(disablePopGesture) forKey:@"__tt_disablePopGesture" association:TLAssociationAssign];
|
||||
if (disablePopGesture && [self.navigationController.childViewControllers containsObject:self]) {
|
||||
self.navigationController.interactivePopGestureRecognizer.delegate = self;
|
||||
}
|
||||
}
|
||||
- (BOOL)disablePopGesture
|
||||
{
|
||||
return [[self associatedObjectForKey:@"__tt_disablePopGesture"] boolValue];
|
||||
}
|
||||
|
||||
#pragma mark - # Delegate
|
||||
//MARK: UIGestureRecognizerDelegate
|
||||
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user