开发者

UIScrollView without paging but with touchesmoved

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:开发者_Python百科(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?


I think I figured it out.

I added:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    [self nacrtajNovuStranicu:(CGContextRef)UIGraphicsGetCurrentContext()]; 
[self setNeedsDisplay];
}

and removed [self nacrtajNovuStranicu:(CGContextRef)UIGraphicsGetCurrentContext()]; from touchesmoved method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜