3

My problem is quite strange but simple. I subclassed a my customer UIScrollView: MyScrollView, where i disabled the scroll:

 self.scrollEnabled = NO; 

that means apart from

 - (void)scrollViewDidScroll:(UIScrollView *)scrollView 

all other UIScrollViewDelegate method won't be called and in MyScrollView i do the content scroll by detecting the user touch movement on screen, that is to say no flipping, no bounces, my implementation is in the touchesMoved:withEvent: method

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject];
   // NSLog(@"touch.phase:%d",touch.phase);
    CGPoint currentPosition = [touch locationInView:self];
    CGPoint lastTouchPosition = [touch previousLocationInView:self];
    CGFloat deltaY = lastTouchPosition.y - currentPosition.y;
    CGFloat contentYOffset = self.contentOffset.y + deltaY;
    [self setContentOffset:CGPointMake(0,contentYOffset) animated:NO];

}

after the user drag movement have been finished, i do my own method according to the content offset of MyScrollView in touchesEnded:withEvent:

 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
 {
     //some implementation according to current content offset
 }

user moves finger on screen, whenever the finger left the screen surface, the touchesEnded:withEvent: get called and i can implement my own method correctly.

BUT, when user move finger on screen surface from inside the screen to outside either on top or bottom, then lift the finger up, the touchesEnded:withEvent: method never got called, it seems like the ios doesn't treat the move out bounds(top or bottom) event as a touches end event, also ios wouldn't know the what is going on when touch is outside it screen bounds

someone may suggest me to detect the current position in touchesMoved:withEvent: to check out whether it is inbounds or not. this MAY WORK WHEN THE MOVEMENT IS VERY SLOW, but when you move very fast, the system can not detect every point position, it seems like the movement is detected in a certain time interval. can any one help me out how could i detect if the user finger has moved out of bounds or not

Roen
  • 116
  • 6

2 Answers2

3

I think the touchesCancelled:withEvent: method will be called !

iSofTom
  • 1,718
  • 11
  • 15
  • 1
    No, the touchesCancelled:withEvent: was not called either – Roen Jul 24 '12 at 03:34
  • Thank you this worked for me, however on a touch drag (or pan) it seams to fire even if the pan is not finished. – Gram Jun 02 '15 at 00:20
1

I have resolved this problem bcs UIScrollView does too much work that we can not handle some event ourselves, fortunately the UIView can detect the touche move out of bounds and will invoke the touchesEnd:withEvent: method. considering that replacing MyScrollView's superclass with UIView has too much work to do, so i figured out a simple way to resolve: i added an TouchActionDetectView subclassed from UIView, whose work is to detect all user touches event and deliver those event to MyScrollView. of course i have to clear the background color of TouchActionDetectView to avoid blocking other view content.

Roen
  • 116
  • 6