开发者

Facing Exception in ScrollView Zooming with paging

I m using Scrolling Madness example in which I m implementing paging and pinch zooming part in my code but my application crashes with an exception.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage setGestureDelegate:]: unrecognized selector sent to instance 0x68a6c00'

    - (CGSize)pageSize {
    CGSize pageSize = scrollView1.frame.size;
    //if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
        //return CGSizeMake(pageSize.height, pageSize.width);
    //else
        return pageSize;
}


- (void)setPagingMode {
    // reposition pages side by side, add them back to the view
    CGSize pageSize = [self pageSize];
    NSUInteger page = 0;
    for(UIView *imgview in [scrollView1 subviews])
    {
        if([imgview isKindOfClass:[UIImageView class]])
        {
            imgview.frame = CGRectMake(pageSize.width * page++, 0, pageSize.width, pageSize.height);
        }
    }

    scrollView1.pagingEnabled = YES;
    scrollView1.showsVerticalScrollIndicator = scrollView1.showsHorizontalScrollIndicator = NO;
    scrollView1.contentSize = CGSizeMake(pageSize.width * [largeImageArr count], pageSize.height);
    scrollView1.contentOffset = CGPointMake(pageSize.width * currentPage, 0);

    scrollViewMode = ScrollViewModePaging;
}

- (void)setZoomingMode {
    NSLog(@"setZoomingMode");
    scrollViewMode = ScrollViewModeZooming; // has to be set early, or else currentPage will be mistakenly reset by scrollViewDidScroll

    // hide all pages except the current one
    //NS开发者_如何学CUInteger page = 0;
    //UIImageView *imgview;
    for(UIView *imgview in [scrollView1 subviews])
    {
        if([imgview isKindOfClass:[UIImageView class]])
        {
            [(UIImageView *)imgview removeFromSuperview];

        }
    }

    //[scrollView1 setEnabledGestures:YES];
    //[scrollView1 setGestureDelegate:self];
    scrollView1.pagingEnabled = NO;
    scrollView1.showsVerticalScrollIndicator = scrollView1.showsHorizontalScrollIndicator = YES;
    pendingOffsetDelta = scrollView1.contentOffset.x;
    scrollView1.bouncesZoom = YES;
}


- (void)setCurrentPage:(NSUInteger)page {
    if (page == currentPage)
        return;
    currentPage = page;
    // in a real app, this would be a good place to instantiate more view controllers -- see SDK examples
}

- (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
    if (scrollViewMode == ScrollViewModePaging)
        [self setCurrentPage:roundf(scrollView1.contentOffset.x / [self pageSize].width)];
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)aScrollView {
    NSLog(@"viewForZoomingInScrollView");
    if (scrollViewMode != ScrollViewModeZooming)
        [self setZoomingMode];
    return [largeImageArr objectAtIndex:currentPage];
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
    //[scrollView setZoomScale:scale+0.01 animated:NO];
    //[scrollView setZoomScale:scale animated:NO];

    NSLog(@"scrollViewDidEndZooming");
    if (scrollView1.zoomScale == scrollView1.minimumZoomScale)
        [self setPagingMode];
    else if (pendingOffsetDelta > 0) {
        UIView *view = [largeImageArr objectAtIndex:currentPage];
        view.center = CGPointMake(view.center.x - pendingOffsetDelta, view.center.y);
        CGSize pageSize = [self pageSize];
        scrollView1.contentOffset = CGPointMake(scrollView1.contentOffset.x - pendingOffsetDelta, scrollView1.contentOffset.y);
        scrollView1.contentSize = CGSizeMake(pageSize.width * scrollView1.zoomScale, pageSize.height * scrollView1.zoomScale);
        pendingOffsetDelta = 0;
    }

}


UIImageView doesn't have a setGestureDelegate method - as you're calling this on a variable called scrollView1 I assume that you didn't expect this to be a UIImage - Simon is probably right; you will have released it by mistake somewhere.

However,

UIScrollView doesn't have the method setGestureDelegate either so you might still have a problem.

What are you trying to do?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜