detect when uiscrollview frame touch the main screen bounds
how can i detect when a UIScrollView
frame intersect with the main screen (when scrolling) in both direction up and down? i was trying to do it like so :
- (void)detectScreenB开发者_Python百科oundsIntersect{
if (CGRectIntersectsRect([myScrollView frame], [[UIScreen mainScreen] bounds])) {
NSLog(@"COLLISION");
}
}
But this doesn't seem to work! Thanks.
Adopt the UIScrollViewDelegate
protocol in the view controller and set the scroll view's delegate to the controller. Adopt the scrollViewDidScroll:
method.
- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
if ( [self hasReachedAVerticalEdge] ) {
NSLog(@"At World's End");
}
}
- (BOOL) hasReachedAVerticalEdge {
CGPoint offset = myScrollView.contentOffSet;
CGSize contentSize = myScrollView.contentSize;
CGFloat height = myScrollView.frame.size.height;
CGFloat width = myScrollView.frame.size.width;
if ( offset.y == 0 ||
(offset.y + height) == contentSize.height ) {
return YES;
}
return NO;
}
Is this what you are looking for?
Checking if an image view falls in the visible portion of the scroll view.
- (BOOL)isContentFrameVisible:(CGRect)aFrame {
CGRect visibleRect = CGRectZero;
visibleRect.origin = myScrollView.offset;
visibleRect.size = myScrollView.frame.size;
if ( CGRectIntersectsRect(visibleRect, aFrame) ) {
return YES;
}
}
精彩评论