Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.m
- // bug
- //
- // Created by on 2/6/13.
- // Copyright (c) 2013 . All rights reserved.
- //
- #import "ViewController.h"
- static UIScrollView * scrollView;
- static UIImageView * imageView;
- static int AllWidth = 4000;
- static int AllHeight = 3000;
- @interface ViewController ()
- @end
- @implementation ViewController
- -(void) writeDebugInfo
- {
- 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);
- NSLog(@"ImageCenterX: %f, ImageCenterY: %f",imageView.center.x
- ,imageView.center.y);
- NSLog(@"ScrollW: %f, ScrollH: %f",scrollView.frame.size.width,scrollView.frame.size.height);
- NSLog(@"ScrollContX: %f; ScrollContentY: %f, ScrollContentW: %f; ScrollContentH: %f",scrollView.contentOffset.x, scrollView.contentOffset.y, scrollView.contentSize.width,scrollView.contentSize.height);
- NSLog(@"ScrollZoomScale: %f",scrollView.zoomScale);
- CGRect tmpRect = [scrollView convertRect:scrollView.bounds fromView:nil];
- NSLog(@"SViewIngX: %f; SViewIngY: %f, SViewIngW: %f; SViewIngH: %f",tmpRect.origin.x, tmpRect.origin.y, tmpRect.size.width,tmpRect.size.height);
- tmpRect = [scrollView convertRect:scrollView.bounds fromView:nil];
- NSLog(@"SViewIngX: %f; SViewIngY: %f, SViewIngW: %f; SViewIngH: %f",tmpRect.origin.x, tmpRect.origin.y, tmpRect.size.width,tmpRect.size.height);
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
- imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, AllWidth, AllHeight)];
- [scrollView addSubview:imageView];
- scrollView.delegate=self;
- scrollView.contentSize = CGSizeMake(AllWidth, AllHeight);
- scrollView.scrollEnabled=TRUE;
- scrollView.contentOffset=CGPointZero;
- scrollView.minimumZoomScale=0.05;
- scrollView.maximumZoomScale = 2; // = 2 ^ 5
- scrollView.zoomScale = (320.0-1)/AllWidth;
- UITapGestureRecognizer *doubleFingerTap =
- [[UITapGestureRecognizer alloc] initWithTarget:self
- action:@selector(handleDoubleTap:)];
- scrollView.backgroundColor = [UIColor blackColor];
- imageView.backgroundColor = [UIColor greenColor] ;
- doubleFingerTap.numberOfTapsRequired = 2;
- [self.view addSubview:scrollView];
- [self.view addGestureRecognizer:doubleFingerTap];
- // Do any additional setup after loading the view, typically from a nib.
- }
- -(UIView *) viewForZoomingInScrollView: (UIScrollView *) sender
- {
- return imageView;
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)handleDoubleTap:(UITapGestureRecognizer *)sender
- {
- if (sender.state == UIGestureRecognizerStateRecognized) {
- NSLog(@"----Tap begin");
- [self writeDebugInfo];
- [scrollView zoomToRect:CGRectMake(0.0, 0.0, AllWidth, AllHeight) animated: NO];
- NSLog(@"----Tap after zoom");
- [self writeDebugInfo];
- NSLog(@"----Tap end");
- NSLog(@"----0.1 second after Tap:");
- [self performSelector:@selector(writeDebugInfo) withObject:nil afterDelay:0.1];
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement