UIScrollView without paging but with touchesmoved
Posted
by BittenApple
on Stack Overflow
See other posts from Stack Overflow
or by BittenApple
Published on 2010-05-25T18:28:57Z
Indexed on
2010/05/25
18:31 UTC
Read the original article
Hit count: 587
I have a UIScrollView that I use to display PDF pages in. I don't want to use paging (yet). I want to display content based on touchesmoved event (so after horizontal swipe).
This works (sort of), but instead of catching a single swipe and showing 1 page, the swipe seems to gets broken into 100s of pieces and 1 swipe acts as if you're moving a slider!
I have no clue what am I doing wrong.
Here's the experimental "display next page" code which works on single taps:
- (void)nacrtajNovuStranicu:(CGContextRef)myContext
{
CGContextTranslateCTM(myContext, 0.0, self.bounds.size.height);
CGContextScaleCTM(myContext, 1.0, -1.0);
CGContextSetRGBFillColor(myContext, 255, 255, 255, 1);
CGContextFillRect(myContext, CGRectMake(0, 0, 320, 412));
size_t brojStranica = CGPDFDocumentGetNumberOfPages(pdfFajl);
if(pageNumber < brojStranica){
pageNumber ++;
}
else{
// kraj PDF fajla, ne listaj dalje.
}
CGPDFPageRef page = CGPDFDocumentGetPage(pdfFajl, pageNumber);
CGContextSaveGState(myContext);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, self.bounds, 0, true);
CGContextConcatCTM(myContext, pdfTransform);
CGContextDrawPDFPage(myContext, page);
CGContextRestoreGState(myContext);
//osvjezi displej
[self setNeedsDisplay];
}
Here's the swiping code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self];
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
[self nacrtajNovuStranicu:(CGContextRef)UIGraphicsGetCurrentContext()];
}
}
The code sits in UIView which displays the PDF content, perhaps I should place it into UIScrollView or is the "display next page" code wrong?
© Stack Overflow or respective owner