Any idea??

Discussion in 'iOS Programming' started by arnieterm, Feb 26, 2009.

  1. arnieterm macrumors regular

    Aug 28, 2008
    I am developing an iphone application just like iPhone Photo application. Like iPhone Photo application i want to implement the swipe gesture to navigate through all images and also pinch zoom gesture to zoom in/out an individual image.
    I am able to implement pinch zoom in/out by adding the UImageView in a UIScrollView and then implementing following delegate:

    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
        return imgV;  // Same, original UIImageView used earlier
    Below is my Views arrangement:


    It's Working perfect.

    I am also able to implement the slide gesture to navigate through images by implementing following code separately:

    - (void)applicationDidFinishLaunching:(UIApplication *)application{
    	scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfImages, scrollView.frame.size.height);
    - (void)scrollViewDidScroll:(UIScrollView *)sender{
    	CGFloat pageWidth = scrollView.frame.size.width;
    	int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
        pageControl.currentPage = page;
        // load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)
        [self loadScrollViewWithPage:page - 1];
        [self loadScrollViewWithPage:page];
        [self loadScrollViewWithPage:page + 1];
    - (void)loadScrollViewWithPage:(int)page {
        if (page < 0) return;
        if (page >= kNumberOfPages) return;
        // replace the placeholder if necessary
        MyViewController *controller = [viewControllers objectAtIndex:page];
        if ((NSNull *)controller == [NSNull null]) {
            controller =
    		[[MyViewController alloc] initWithPageNumber:page];
            [viewControllers replaceObjectAtIndex:page withObject:controller];
            [controller release];
        // add the controller's view to the scroll view
        if (nil == controller.view.superview) {
            CGRect frame = scrollView.frame;
            frame.origin.x = frame.size.width * page;
            frame.origin.y = 0;
            controller.view.frame = frame;
            [scrollView addSubview:controller.view];
    Below is my Views arrangement in this situation:


    arrangement for MyView:

    Now when i try to combine both solutions, so that it would behave like iPhone Photo app then I am able to have slide gesture but i can not have pinch zoom. Please help, It's Urgent.

Share This Page