Zoomverhalten wie bei den Bilder im iPhone: pagingEnabled + maximumZoomScale

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Zoomverhalten wie bei den Bilder im iPhone: pagingEnabled + maximumZoomScale

    Hallo zusammen,

    wie bekomme ich es denn hin, dass ich mehrere Bilder (wie im oberen Beispiel von Apple "Scrolling") "durchblättern" kann, aber diese auch gleichzeitig in der Größe (Zoom) verändern kann. Also so ein Verhalten, wie man es auf dem iPhone vom Bilderbrowser kennt?

    Danke schon mal :)
  • danke für die schnelle Antwort. Klappt soweit auch schon ganz prima.

    Habe jetzt noch eine Zusatzfrage: bei mir sind es keine Bilder, die in den
    UIView gelegt werden, sonder UIViews, die PDFs darstellen.
    Kann ich
    diese UIViews dazu bewegen, nach dem zoomen, ihre drawLayer Methode
    aufzurufen?

    Habe also dein Konstrukt von oben, nur dass nicht
    UIImageViews im UIView liegen, sondern weitere UIViews (OnePDFSite).

    OnePDFSite.h


    Quellcode

    1. #import
    2. <UIKit/UIKit.h>
    3. @interface OnePDFSite : UIView
    4. <UIScrollViewDelegate> {
    5. UIView *myContentView;
    6. UIScrollView *scrollView;
    7. CGPDFDocumentRef myDocumentRef;
    8. CGPDFPageRef myPageRef;
    9. NSInteger myPageNumber;
    10. }
    11. @property(readwrite)NSInteger
    12. myPageNumber;
    13. - (id)myInitWithFrame:(CGRect)frame
    14. andPageNumber:(NSInteger)pNr;
    15. @end
    Alles anzeigen


    OnePDFSite.m

    Quellcode

    1. //
    2. // OnePDFSite.m
    3. // PDFView2
    4. //
    5. // Created by Achim Bruns on 12.07.10.
    6. // Copyright 2010 __MyCompanyName__. All rights reserved.
    7. //
    8. #import <QuartzCore/QuartzCore.h>
    9. #import "OnePDFSite.h"
    10. @implementation OnePDFSite
    11. @synthesize myPageNumber;
    12. - (id)myInitWithFrame:(CGRect)frame andPageNumber:(NSInteger)pNr
    13. {
    14. if ((self = [super initWithFrame:frame])) {
    15. CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("meinePDFDatei.pdf"), NULL, NULL);
    16. myDocumentRef = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
    17. myPageRef = CGPDFDocumentGetPage(myDocumentRef, pNr);
    18. CGRect pageRect = CGRectIntegral(CGPDFPageGetBoxRect(myPageRef, kCGPDFCropBox));
    19. //NSLog(@"pageRect %@",NSStringFromCGRect(pageRect));
    20. CATiledLayer *tiledLayer = [CATiledLayer layer];
    21. tiledLayer.delegate = self;
    22. tiledLayer.tileSize = CGSizeMake(1024.0, 1024.0);
    23. tiledLayer.levelsOfDetail = 1000;
    24. tiledLayer.levelsOfDetailBias = 1000;
    25. tiledLayer.frame = pageRect;
    26. myContentView = [[UIView alloc] initWithFrame:pageRect];
    27. myContentView.tag = 1;
    28. [myContentView.layer addSublayer:tiledLayer];
    29. CGRect viewFrame = self.frame;
    30. viewFrame.origin = CGPointZero;
    31. scrollView = [[UIScrollView alloc] initWithFrame:viewFrame];
    32. scrollView.delegate = self;
    33. scrollView.contentSize = pageRect.size;
    34. scrollView.maximumZoomScale = 5;
    35. //NSLog(@"myPageRef in One Site %@",myPageRef);
    36. [scrollView addSubview:myContentView];
    37. //[self addSubview:scrollView];
    38. }
    39. return self;
    40. }
    41. /*
    42. -(void)drawInContext:(CGContextRef)context
    43. {
    44. NSLog(@"drawInContext");
    45. }
    46. */
    47. - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
    48. {
    49. NSLog(@"oneSite drawLayer myPageRef %@",myPageRef);
    50. CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
    51. CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx));
    52. CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height);
    53. CGContextScaleCTM(ctx, 1.0, -1.0);
    54. CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(myPageRef, kCGPDFCropBox, layer.bounds, 0, true));
    55. CGContextDrawPDFPage(ctx, myPageRef);
    56. }
    57. - (void)drawRect:(CGRect)rect {
    58. // Drawing code
    59. NSLog(@"drawRect");
    60. CGContextRef ctx = UIGraphicsGetCurrentContext();
    61. CGContextClearRect(ctx, rect);
    62. CGContextSetRGBFillColor(ctx, 1.0, 0.0, 0.0, 1.0);
    63. CGContextFillRect(ctx, rect);
    64. }
    65. - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
    66. {
    67. NSLog(@"viewForZoomingInScrollView");
    68. return myContentView;
    69. }
    70. /*
    71. // Only override drawRect: if you perform custom drawing.
    72. // An empty implementation adversely affects performance during animation.
    73. - (void)drawRect:(CGRect)rect {
    74. // Drawing code
    75. }
    76. */
    77. - (void)dealloc {
    78. [super dealloc];
    79. myPageNumber = 0;
    80. }
    81. @end
    Alles anzeigen