@@ -23,8 +23,6 @@ @interface YNPageViewController () <UIScrollViewDelegate, YNPageScrollMenuViewDe
2323@property (nonatomic , strong ) NSMutableDictionary *displayDictM;
2424// / 字典控制器的字典
2525@property (nonatomic , strong ) NSMutableDictionary *cacheDictM;
26- // / 缓存观察者对象
27- @property (nonatomic , strong ) NSMutableDictionary *observeCacheDictM;
2826// / 当前显示的页面
2927@property (nonatomic , strong ) UIScrollView *currentScrollView;
3028// / 当前控制器
@@ -86,7 +84,6 @@ - (instancetype)initPageViewControllerWithControllers:(NSArray *)controllers
8684 self.config = config ?: [YNPageConfigration defaultConfig ];
8785 self.displayDictM = @{}.mutableCopy ;
8886 self.cacheDictM = @{}.mutableCopy ;
89- self.observeCacheDictM = @{}.mutableCopy ;
9087 return self;
9188}
9289
@@ -156,19 +153,6 @@ - (void)initViewControllerWithIndex:(NSInteger)index {
156153 [self addViewControllerToParent: cacheViewController ?: self .controllersM[index] index: index];
157154
158155}
159- // / 控制器销毁时
160- - (void )willMoveToParentViewController : (UIViewController *)parent {
161- if (!parent) {
162- if ([self isSuspensionBottomStyle ] || [self isSuspensionTopStyle ]) {
163- for (int i = 0 ; i < self.cacheDictM .allKeys .count ; i++) {
164- NSString *title = self.cacheDictM .allKeys [i];
165- NSInteger index = [self getPageIndexWithTitle: title];
166- [self removeObservePathWithIndex: index];
167- }
168- }
169- }
170- }
171-
172156// / 添加到父类控制器中
173157- (void )addViewControllerToParent : (UIViewController *)viewController index : (NSInteger )index {
174158
@@ -192,9 +176,6 @@ - (void)addViewControllerToParent:(UIViewController *)viewController index:(NSIn
192176 if (![self .cacheDictM objectForKey: title]) {
193177 // / 设置TableView内容偏移
194178 scrollView.contentInset = UIEdgeInsetsMake (_insetTop, 0 , 3 * _insetTop, 0 );
195- // / 添加观察者contentSize
196- [scrollView addObserver: self forKeyPath: @" contentSize" options: NSKeyValueObservingOptionNew context: (__bridge void * _Nullable)(scrollView)];
197- [self .observeCacheDictM setValue: scrollView forKey: title];
198179 }
199180 if ([self isSuspensionBottomStyle ]) {
200181 scrollView.scrollIndicatorInsets = UIEdgeInsetsMake (_insetTop, 0 , 0 , 0 );
@@ -508,7 +489,6 @@ - (void)removePageControllerWithIndex:(NSInteger)index {
508489 [self .titlesM removeObject: self .titlesM[index]];
509490 [self .controllersM removeObject: self .controllersM[index]];
510491
511- [self removeObservePathWithIndex: index];
512492 [self .cacheDictM removeObjectForKey: title];
513493
514494 [self updateViewWithIndex: pageIndex];
@@ -945,15 +925,6 @@ - (UIScrollView *)getScrollViewWithPageIndex:(NSInteger)pageIndex {
945925 return scrollView;
946926}
947927
948- // / 移除观察者
949- - (void )removeObservePathWithIndex : (NSInteger )index {
950- NSString *title = [self titleWithIndex: index];
951- UIScrollView *scrollView = self.observeCacheDictM [title];
952- if (scrollView) {
953- [scrollView removeObserver: self forKeyPath: @" contentSize" ];
954- [self .observeCacheDictM removeObjectForKey: title];
955- }
956- }
957928// / 处理头部伸缩
958929- (void )headerScaleWithOffsetY : (CGFloat)offsetY {
959930
0 commit comments