研究2
從- (void)_frameOrBoundsChanged
裡面還沒看到跟WKContentView或WKScrollView相關的內容,研究一下後再從[self _scheduleVisibleContentRectUpdate]繼續往下看:
- (void)_scheduleVisibleContentRectUpdate
{
// For visible rect updates not associated with a specific UIScrollView, just consider our own scroller.
[self _scheduleVisibleContentRectUpdateAfterScrollInView:_scrollView.get()];
}
- (void)_scheduleVisibleContentRectUpdateAfterScrollInView:(UIScrollView *)scrollView
{
_visibleContentRectUpdateScheduledFromScrollViewInStableState = [self _scrollViewIsInStableState:scrollView];
if (_hasScheduledVisibleRectUpdate)
return;
_hasScheduledVisibleRectUpdate = YES;
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
CATransactionPhase transactionPhase = [CATransaction currentPhase];
if (transactionPhase == kCATransactionPhaseNull || transactionPhase == kCATransactionPhasePreLayout) {
[self _addUpdateVisibleContentRectPreCommitHandler];
return;
}
#endif
dispatch_async(dispatch_get_main_queue(), [retainedSelf = retainPtr(self)] {
WKWebView *webView = retainedSelf.get();
if (![webView _isValid])
return;
[webView _addUpdateVisibleContentRectPreCommitHandler];
});
}
- (void)_addUpdateVisibleContentRectPreCommitHandler
{
auto retainedSelf = retainPtr(self);
[CATransaction addCommitHandler:[retainedSelf] {
WKWebView *webView = retainedSelf.get();
if (![webView _isValid])
return;
[webView _updateVisibleContentRects];
webView->_hasScheduledVisibleRectUpdate = NO;
} forPhase:kCATransactionPhasePreCommit];
}
看到[webView _updateVisibleContentRects]從function名稱推斷這可能是畫面更新的關鍵,於是繼續往下看
未完繼續...