Advertisement
Guest User

Untitled

a guest
Feb 6th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  ViewController.m
  3. //  bug
  4. //
  5. //  Created by on 2/6/13.
  6. //  Copyright (c) 2013 . All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10. static UIScrollView * scrollView;
  11. static UIImageView * imageView;
  12. static int AllWidth = 4000;
  13. static int AllHeight = 3000;
  14. @interface ViewController ()
  15.  
  16.  
  17. @end
  18.  
  19.  
  20. @implementation ViewController
  21.  
  22. -(void) writeDebugInfo
  23. {
  24.     NSLog(@"ImageX: %f, ImageY: %f; ImageW: %f; ImageH: %f",imageView.frame.origin.x,imageView.frame.origin.y,imageView.frame.size.width,imageView.frame.size.height);
  25.     NSLog(@"ImageCenterX: %f, ImageCenterY: %f",imageView.center.x
  26.           ,imageView.center.y);
  27.     NSLog(@"ScrollW: %f, ScrollH: %f",scrollView.frame.size.width,scrollView.frame.size.height);
  28.    
  29.     NSLog(@"ScrollContX: %f; ScrollContentY: %f, ScrollContentW: %f; ScrollContentH: %f",scrollView.contentOffset.x, scrollView.contentOffset.y, scrollView.contentSize.width,scrollView.contentSize.height);
  30.     NSLog(@"ScrollZoomScale: %f",scrollView.zoomScale);
  31.    
  32.     CGRect tmpRect = [scrollView convertRect:scrollView.bounds fromView:nil];
  33.     NSLog(@"SViewIngX: %f; SViewIngY: %f, SViewIngW: %f; SViewIngH: %f",tmpRect.origin.x, tmpRect.origin.y, tmpRect.size.width,tmpRect.size.height);
  34.    
  35.     tmpRect = [scrollView convertRect:scrollView.bounds fromView:nil];
  36.     NSLog(@"SViewIngX: %f; SViewIngY: %f, SViewIngW: %f; SViewIngH: %f",tmpRect.origin.x, tmpRect.origin.y, tmpRect.size.width,tmpRect.size.height);
  37. }
  38. - (void)viewDidLoad
  39. {
  40.     [super viewDidLoad];
  41.     scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
  42.     imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, AllWidth, AllHeight)];
  43.     [scrollView addSubview:imageView];
  44.     scrollView.delegate=self;
  45.     scrollView.contentSize = CGSizeMake(AllWidth, AllHeight);
  46.  
  47.     scrollView.scrollEnabled=TRUE;
  48.     scrollView.contentOffset=CGPointZero;
  49.     scrollView.minimumZoomScale=0.05;
  50.     scrollView.maximumZoomScale = 2; // = 2 ^ 5
  51.     scrollView.zoomScale = (320.0-1)/AllWidth;
  52.     UITapGestureRecognizer *doubleFingerTap =
  53.     [[UITapGestureRecognizer alloc] initWithTarget:self
  54.                                             action:@selector(handleDoubleTap:)];
  55.     scrollView.backgroundColor = [UIColor blackColor];
  56.     imageView.backgroundColor = [UIColor greenColor] ;
  57.     doubleFingerTap.numberOfTapsRequired = 2;
  58.     [self.view addSubview:scrollView];
  59.     [self.view addGestureRecognizer:doubleFingerTap];
  60.  
  61.    
  62.     // Do any additional setup after loading the view, typically from a nib.
  63. }
  64. -(UIView *) viewForZoomingInScrollView: (UIScrollView *) sender
  65. {
  66.     return imageView;
  67. }
  68. - (void)didReceiveMemoryWarning
  69. {
  70.     [super didReceiveMemoryWarning];
  71.     // Dispose of any resources that can be recreated.
  72. }
  73.  
  74. - (void)handleDoubleTap:(UITapGestureRecognizer *)sender
  75. {
  76.     if (sender.state == UIGestureRecognizerStateRecognized) {
  77.         NSLog(@"----Tap begin");
  78.         [self writeDebugInfo];
  79.        
  80.         [scrollView zoomToRect:CGRectMake(0.0,  0.0, AllWidth, AllHeight) animated: NO];
  81.         NSLog(@"----Tap after zoom");
  82.         [self writeDebugInfo];
  83.         NSLog(@"----Tap end");
  84.         NSLog(@"----0.1 second after Tap:");
  85.         [self performSelector:@selector(writeDebugInfo) withObject:nil afterDelay:0.1];
  86.        
  87.     }
  88. }
  89. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement