我有一个UIScrollView加载三个不同的页面.当我放大页面,并缩小到原始大小时,应用程序停止让我在页面之间滚动,就像分页被禁用.当缩小到原始大小时,我该怎么做才能重新启用分页(Scale == 1)?
这是我的代码
这是我的代码
- (void)viewDidLoad { [ScView setMaximumZoomScale : 2.0f]; [ScView setMinimumZoomScale : 1.0f]; ScView.contentSize = CGSizeMake(1024*3,1.0); ScView.pagingEnabled = YES; ScView.clipsToBounds = YES; ScView.delegate = self; ScView.showsHorizontalScrollIndicator = NO; ScView.showsVerticalScrollIndicator = NO; [super viewDidLoad]; [self returnImages]; } -(void)returnImages{ for (pageNumber = 1; pageNumber <= 3; pageNumber++) { imagen = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",pageNumber]]]; imagen.frame = CGRectMake((pageNumber-1)*1024,1024,768); [ScView addSubview:imagen]; } } // - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ return ScView; // return [imagen initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",pageNumber]]]; } - (void)scrollViewWillBeginZooming:(UIScrollView *)myScrollView withView:(UIView *)view { NSLog(@"Scroll Will Begin"); ScView.scrollEnabled = YES; } - (void)scrollViewDidEndZooming:(UIScrollView *)myScrollView withView:(UIView *)view atScale:(float)scale { if(scale == 1) { ScView.scrollEnabled = YES; ScView.pagingEnabled = YES; [self returnImages]; NSLog(@"Scrolol will end"); //ScView.maximumZoomScale = 2.0f; // [super viewDidLoad]; [self returnImages]; } }
任何想法将受到高度赞赏..
解决方法
要获得正确的分页和缩放,您必须将每个页面的UIScrollView嵌入到父UIScrollView中.此组合允许您同时使用分页和内部滚动.
下面是UIViewController的示例,其中包含父滚动视图和三个嵌入的可缩放页面.
#define VIEW_FOR_ZOOM_TAG (1) @implementation SVViewController - (void)viewDidLoad { [super viewDidLoad]; UIScrollView *mainScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds]; mainScrollView.pagingEnabled = YES; mainScrollView.showsHorizontalScrollIndicator = NO; mainScrollView.showsVerticalScrollIndicator = NO; CGRect innerScrollFrame = mainScrollView.bounds; for (NSInteger i = 0; i < 3; i++) { UIImageView *imageForZooming = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"page%d",i + 1]]]; imageForZooming.tag = VIEW_FOR_ZOOM_TAG; UIScrollView *pageScrollView = [[UIScrollView alloc] initWithFrame:innerScrollFrame]; pageScrollView.minimumZoomScale = 1.0f; pageScrollView.maximumZoomScale = 2.0f; pageScrollView.zoomScale = 1.0f; pageScrollView.contentSize = imageForZooming.bounds.size; pageScrollView.delegate = self; pageScrollView.showsHorizontalScrollIndicator = NO; pageScrollView.showsVerticalScrollIndicator = NO; [pageScrollView addSubview:imageForZooming]; [mainScrollView addSubview:pageScrollView]; if (i < 2) { innerScrollFrame.origin.x += innerScrollFrame.size.width; } } mainScrollView.contentSize = CGSizeMake(innerScrollFrame.origin.x + innerScrollFrame.size.width,mainScrollView.bounds.size.height); [self.view addSubview:mainScrollView]; } - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return [scrollView viewWithTag:VIEW_FOR_ZOOM_TAG]; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (BOOL)shouldAutorotate { return NO; } @end