判斷view 是否顯示在scrollview 上
阿新 • • 發佈:2019-02-18
判斷view 是否顯示在scrollview 上
/*
判斷view 是否顯示在scrollview 上
targetView 要判斷是否在scrollview 上顯示的targetView
horizontalScroll scrollview 是橫向還是垂直滑動 ,yes 橫向 no 垂直
*/
(BOOL)displayedInScreen:(UIView*)targetView horizontalScroll:(BOOL)horizontalScroll{
BOOL show = YES;
CGRect f = self.frame;
if(horizontalScroll == YES){
f.origin.x = self.contentOffset.x;
}else{
f.origin.y = self.contentOffset.y;
}
CGRect r = [self.superview convertRect:targetView.frame toView:self.superview];
if(CGRectIntersectsRect(f, r)) {
// view is visible
show = YES;
}else
show = NO;return show;
}