zoom event with array of images of imageview in uiscrollview

Discussion in 'iOS Programming' started by iRavan, Jul 5, 2011.

  1. iRavan, Jul 5, 2011
    Last edited by a moderator: Jul 6, 2011

    iRavan macrumors newbie

    Joined:
    Jul 5, 2011
    #1
    Code:
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad 
    {
    	UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
    	tapGesture.numberOfTapsRequired = 1;
    	tapGesture.numberOfTouchesRequired = 1;
    	
    	
        scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    	
        int numberOfImages = 32;
        CGFloat currentX = 0.0f;
    	
        for (int i=1; i <= numberOfImages; i++) {
    		
            // create image
            NSString *imageName = [NSString stringWithFormat:@"page-%d.jpg", i];
            UIImage *image = [UIImage imageNamed:imageName];
            imageView = [[UIImageView alloc] initWithImage:image];
    		
            // put image on correct position
            CGRect rect = imageView.frame;
            rect.origin.x = currentX;
            imageView.frame = rect;
    		
            // update currentX
            currentX +=454; //mageView.frame.size.width;
    		
            [scrollView addSubview:imageView];
            [imageView release];
        }
    	[scrollView addGestureRecognizer:tapGesture];
    
        scrollView.contentSize = CGSizeMake(currentX, 800);
    	scrollView.pagingEnabled=YES;
    	scrollView.userInteractionEnabled = YES;
    	scrollView.maximumZoomScale = 15;
    	scrollView.minimumZoomScale = 0.5;
    	scrollView.bounces = NO;
    	scrollView.bouncesZoom = NO;
    	scrollView.delegate = self;
    	
        scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
        [self.view addSubview:scrollView];
        [scrollView release];
        [super viewDidLoad];
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return YES;
    }
    
    
    
    -(void)tapDetected:(UIGestureRecognizer*)recognizer{
    	NSLog(@"tap detected.");
    	CGPoint point = [recognizer locationInView:nil];
    	
    	NSLog(@"x = %f y = %f", point.x, point.y );
    }
    
    -(UIView*) viewForZoomingInScrollView:(UIScrollView *)scrollView {
    	return [[self.view subviews] objectAtIndex:0];
    }
    
    
    - (void)didReceiveMemoryWarning {
    	// Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    	
    	// Release any cached data, images, etc that aren't in use.
    }
    
    - (void)viewDidUnload {
    	self.scrollView = nil;
    	self.imageView = nil;
    }
    
     
  2. xStep, Jul 5, 2011
    Last edited by a moderator: Jul 6, 2011

    xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #2
    Describe more of what it is you are trying to accomplish.
     
  3. jiminaus, Jul 5, 2011
    Last edited by a moderator: Jul 6, 2011

    jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
  4. jnoxx, Jul 6, 2011
    Last edited by a moderator: Jul 6, 2011

    jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    I don't see a proper question asked. *sigh..*
     

Share This Page