Commit a9e1d4812989613db234334f3ed86eb2b86b67c9

Authored by yanglingyu
1 parent 0af8ba95

no message

CNLiveVideoClassifyKit/Classes/ClassifyCategory/Controller/CNLiveListController.m
... ... @@ -88,18 +88,27 @@
88 88 UIViewController *vc = self.childViewControllers[0];
89 89 if (([CNLiveListController searchProperties:[vc class] string:@"webView"]||[CNLiveListController searchProperties:[vc.superclass class] string:@"webView"])&&[vc valueForKey:@"webView"]&&[[vc valueForKey:@"webView"] isKindOfClass:[WKWebView class]]) {
90 90 WKWebView *webView = (WKWebView *)[vc valueForKey:@"webView"];
91   - [webView.scrollView removeObserver:self forKeyPath:@"contentOffset"];
  91 + if ([self isObj:webView.scrollView hasObserverKey:@"contentOffset"]) {
  92 + [webView.scrollView removeObserver:self forKeyPath:@"contentOffset"];
  93 + }
  94 +
92 95 if ([webView.scrollView valueForKey:@"mj_header"]) {
93 96 id header = [webView.scrollView valueForKey:@"mj_header"];
94   - [header removeObserver:self forKeyPath:@"state"];
  97 + if ([self isObj:header hasObserverKey:@"state"]) {
  98 + [header removeObserver:self forKeyPath:@"state"];
  99 + }
95 100 }
96 101  
97 102 }else if ([CNLiveListController searchProperties:[vc class] string:@"collectionView"]&&[vc valueForKey:@"collectionView"] && [[vc valueForKey:@"collectionView"] isKindOfClass:[UICollectionView class]]){
98 103 UICollectionView *collectionView = (UICollectionView *)[vc valueForKey:@"collectionView"];
99   - [collectionView removeObserver:self forKeyPath:@"contentOffset"];
  104 + if ([self isObj:collectionView hasObserverKey:@"contentOffset"]) {
  105 + [collectionView removeObserver:self forKeyPath:@"contentOffset"];
  106 + }
100 107 if ([collectionView valueForKey:@"mj_header"]) {
101 108 id header = [collectionView valueForKey:@"mj_header"];
102   - [header removeObserver:self forKeyPath:@"state"];
  109 + if ([self isObj:header hasObserverKey:@"state"]) {
  110 + [header removeObserver:self forKeyPath:@"state"];
  111 + }
103 112 }
104 113 }
105 114 }
... ... @@ -117,6 +126,25 @@
117 126 }
118 127 return NO;
119 128 }
  129 +-(BOOL)isObj:(NSObject *)obj hasObserverKey:(NSString *)keyPath{
  130 + if (obj == nil) {
  131 + return NO;
  132 + }
  133 + if (obj.observationInfo == nil) {
  134 + return NO;
  135 + }
  136 + NSObject *observances = [((__bridge NSObject*)(obj.observationInfo))valueForKeyPath:@"observances"];
  137 + if ([observances isKindOfClass:[NSArray class]]) {
  138 + for (NSObject *observance in (NSArray *)observances) {
  139 + NSString *inKeyPath = [NSString stringWithFormat:@"Key path: %@",keyPath];
  140 + NSString *objString = [NSString stringWithFormat:@"%@",observance];
  141 + if ([objString containsString:inKeyPath]) {
  142 + return YES;
  143 + }
  144 + }
  145 + }
  146 + return NO;
  147 +}
120 148 #pragma mark - KVO
121 149 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
122 150 {
... ... @@ -138,7 +166,7 @@
138 166 if (contentPointY>self.contentOffetY&&contentPointY>0) {
139 167 [[CNLiveListManager shareListManager] firstHeaderUp:YES];
140 168 self.contentOffetY = contentPointY;
141   - }else if (self.contentOffetY > contentPointY &&contentPointY<scrollView.contentSize.height/2){
  169 + }else if (self.contentOffetY > contentPointY &&contentPointY<scrollView.contentSize.height-scrollView.height){
142 170 self.contentOffetY = contentPointY;
143 171 [[CNLiveListManager shareListManager] firstHeaderUp:NO];
144 172 }
... ...