Commit a9e1d4812989613db234334f3ed86eb2b86b67c9
1 parent
0af8ba95
no message
Showing
1 changed file
with
33 additions
and
5 deletions
CNLiveVideoClassifyKit/Classes/ClassifyCategory/Controller/CNLiveListController.m
| @@ -88,18 +88,27 @@ | @@ -88,18 +88,27 @@ | ||
| 88 | UIViewController *vc = self.childViewControllers[0]; | 88 | UIViewController *vc = self.childViewControllers[0]; |
| 89 | if (([CNLiveListController searchProperties:[vc class] string:@"webView"]||[CNLiveListController searchProperties:[vc.superclass class] string:@"webView"])&&[vc valueForKey:@"webView"]&&[[vc valueForKey:@"webView"] isKindOfClass:[WKWebView class]]) { | 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 | WKWebView *webView = (WKWebView *)[vc valueForKey:@"webView"]; | 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 | if ([webView.scrollView valueForKey:@"mj_header"]) { | 95 | if ([webView.scrollView valueForKey:@"mj_header"]) { |
| 93 | id header = [webView.scrollView valueForKey:@"mj_header"]; | 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 | }else if ([CNLiveListController searchProperties:[vc class] string:@"collectionView"]&&[vc valueForKey:@"collectionView"] && [[vc valueForKey:@"collectionView"] isKindOfClass:[UICollectionView class]]){ | 102 | }else if ([CNLiveListController searchProperties:[vc class] string:@"collectionView"]&&[vc valueForKey:@"collectionView"] && [[vc valueForKey:@"collectionView"] isKindOfClass:[UICollectionView class]]){ |
| 98 | UICollectionView *collectionView = (UICollectionView *)[vc valueForKey:@"collectionView"]; | 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 | if ([collectionView valueForKey:@"mj_header"]) { | 107 | if ([collectionView valueForKey:@"mj_header"]) { |
| 101 | id header = [collectionView valueForKey:@"mj_header"]; | 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,6 +126,25 @@ | ||
| 117 | } | 126 | } |
| 118 | return NO; | 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 | #pragma mark - KVO | 148 | #pragma mark - KVO |
| 121 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context | 149 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context |
| 122 | { | 150 | { |
| @@ -138,7 +166,7 @@ | @@ -138,7 +166,7 @@ | ||
| 138 | if (contentPointY>self.contentOffetY&&contentPointY>0) { | 166 | if (contentPointY>self.contentOffetY&&contentPointY>0) { |
| 139 | [[CNLiveListManager shareListManager] firstHeaderUp:YES]; | 167 | [[CNLiveListManager shareListManager] firstHeaderUp:YES]; |
| 140 | self.contentOffetY = contentPointY; | 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 | self.contentOffetY = contentPointY; | 170 | self.contentOffetY = contentPointY; |
| 143 | [[CNLiveListManager shareListManager] firstHeaderUp:NO]; | 171 | [[CNLiveListManager shareListManager] firstHeaderUp:NO]; |
| 144 | } | 172 | } |