我正在使用Scrolling Madness示例,其中我在我的代码中实现分页和缩放缩放部分,但我的应用程序崩溃时出现异常。
由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [UIImage setGestureDelegate:]:无法识别的选择器发送到实例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
//NSUInteger 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;
}
}
答案 0 :(得分:0)
UIImageView没有setGestureDelegate方法 - 因为你在一个名为scrollView1的变量上调用它我假设你没想到这是一个UIImage - Simon可能是正确的;你会在某个地方错误地释放它。
然而,
UIScrollView没有setGestureDelegate方法,因此您可能仍有问题。
你想做什么?