监听自定义View的SuperViewController是否被Push或者pop
在开发SDK的过程当中需要在viewcontroller中的view完全删除,需要监听当前的Viewcontroller是否退出。
尝试了很多方式,有一个navigationviewcontroller的一个代理协议帮助了我, UINavigationControllerDelegate
在想要监听view中实现这个协议;
- (instancetype)initWithFrame:(CGRect)frame SelfController:(UIViewController*)SelfViewController{ self = [super initWithFrame:frame]; if(self){ SelfViewController.navigationController.delegate = self; } return self; }
别忘了在声明文件中遵守UINavigationControllerDelegate 协议;
自定义类:UIView<UINavigationControllerDelegate>
然后实现该方法:
- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC NS_AVAILABLE_IOS(7_0){ switch (operation) { case UINavigationControllerOperationNone: { } break; case UINavigationControllerOperationPush:{ } break; case UINavigationControllerOperationPop:{ [self removeAllobjectNofi]; } break; default: break; } return nil; }
在上述方法中判断如果是push 做什么操作,pop做什么操作, none是没有操作默认;
好了,这只不过是开发过程当中的一个小问题, 以前很少写东西,基本上都是写一些笔记, 印象笔记大家应该都有, 从今天开始,我会时不时的加入一些我工作当中遇到的问题,和是如何解决的,如果自己写笔记只不过是贴一些代码,如果写文章既能锻炼自己的表达能力,又能提高自己的技术水准何乐而不为!

浙公网安备 33010602011771号