내가 KVO에 대해 얻지 못하는 무언가가 있어야합니다. UIScrollView를 스크롤하여 UITableView를 스크롤하려고합니다. 오프셋 번역은 정확하지만 UIScrollView가 스크롤을 마친 후에 UITableView 스크롤이 발생합니다. 여기 KVO가 동시에 작동하지 않아야합니까?
내 관측 코드 :- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
AILog(@"observeValueForKeyPath:%@ ofObject:%@", keyPath, NSStringFromClass([object class]));
static BOOL isObservingContentOffsetChange = NO;
if ([keyPath isEqualToString:@"contentOffset"]) {
if ([object isEqual:self.scrollView]) {
if (isObservingContentOffsetChange) {
return;
}
isObservingContentOffsetChange = YES;
CGPoint offset = [[change valueForKey:NSKeyValueChangeNewKey] CGPointValue];
NSDate *offsetDay = [self dayForScrollViewOffset:offset];
if (offsetDay) {
AILog(@"offset (%.2f, %.2f)", offset.x, offset.y);
AILog(@"offsetDay %@", [df stringFromDate:offsetDay]);
NSIndexPath *offsetIndexPath = [self indexPathForDay:offsetDay];
AILog(@"offsetIndexPath (%d, %d)", (int)offsetIndexPath.section, (int)offsetIndexPath.row);
if (offsetIndexPath) {
CGRect rect = [self.tableView rectForSection:offsetIndexPath.section];
[self.tableView setContentOffset:CGPointMake(0, rect.origin.y) animated:YES];
AILog(@"----------------------------------------------");
}
} else {
AILog(@"nil offset day");
}
}
isObservingContentOffsetChange = NO;
return;
}
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
그리고 여기이 보여 콘솔 로그가 예상대로 작동된다 :
014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1526.50, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Sunday, 19/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (2, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1520.00, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Sunday, 19/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (2, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1514.00, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Sunday, 19/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (2, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1508.50, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Sunday, 19/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (2, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1503.50, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Sunday, 19/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (2, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1498.00, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Sunday, 19/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (2, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1493.00, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Sunday, 19/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (2, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1488.00, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Sunday, 19/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (2, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1483.50, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Saturday, 18/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (3, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1479.00, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Saturday, 18/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (3, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1474.50, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Saturday, 18/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (3, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1470.00, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Saturday, 18/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (3, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1466.00, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Saturday, 18/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (3, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1462.00, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Saturday, 18/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (3, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1458.50, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Saturday, 18/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (3, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1454.50, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Saturday, 18/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (3, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1450.50, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Saturday, 18/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (3, 0)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> ----------------------------------------------
2014-10-21 17:44:53 +0000 : BPTimeViewController --> observeValueForKeyPath:contentOffset ofObject:UIScrollView
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offset (1447.00, 0.00)
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetDay Saturday, 18/10/2014
2014-10-21 17:44:53 +0000 : BPTimeViewController --> offsetIndexPath (3, 0)
하지만 jQuery과 스크롤 시작에만 모든 콘텐츠 오프셋을 계산 한 후 UIScrollView가 감속을 끝내면 UIScrollView 대리자 메서드에는 아무 것도 없습니다. 그 이유를 알고 계십니까?
'UIScrollViewDelegate' 메소드를 사용하지 않을 이유가 있습니까? '- scrollViewDidScroll'과 같이, 예를 들면? –
예, 있습니다. 그리고 이것은 요점이 아닙니다. 나는 KVO를 필요로하고 싶다. 그리고 나는이 질문에 또 다른 질문을하지 않았다. 감사. –
은 동기식으로 실행하고 UI를 차단하는 것과 같습니다. – vikingosegundo