我是iPhone开发的新手。我在UIScrollView(zoomscrollView)中包含的UIImageView中有一个图像,它包含在另一个UIScrollView(scrollViewgalery)中。
我的问题是,在触摸第一个滚动视图(即zoomScrollview)时,它会向上移动。
答案 0 :(得分:2)
I Hope you need a view similar to photos gallery view. Here u will need a main scrollviewGallery and inside it your scrollviewZoom whose height should be same as scrollViewGallery for horizontal scroll and scrollViewZooms width should be same as scrollViewGallery for vertical scroll. Also Make sure u have enabled pagination for scrollViewGallery.
Your sample code goes here
[_scrollView setDelegate:self];
int index=0;
for (NSString* stringImageName in self.arrayGalleryImages)
{
UIScrollView *imgScroll=[[UIScrollView alloc]initWithFrame:CGRectMake(index*CGRectGetWidth(_scrollView.frame),0,CGRectGetWidth(_scrollView.frame),CGRectGetHeight(_scrollView.frame))];
[imgScroll setDelegate:self];
[imgScroll setTag:index];
[imgScroll setScrollEnabled:NO];
[imgScroll setMinimumZoomScale:1.0];
[imgScroll setMaximumZoomScale:3.0];
[imgScroll setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
UIButton *btnGallery=[[UIButton alloc] initWithFrame: imgScroll.bounds];
[btnGallery addTarget:self action:@selector(gotoFullScreenGallery) forControlEvents:UIControlEventTouchUpInside];
[btnGallery setAdjustsImageWhenHighlighted:NO];
[btnGallery setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
[btnGallery setTag:index];
[[btnGallery imageView] setContentMode: UIViewContentModeScaleAspectFit];
[btnGallery setImage:[UIImage imageNamed:stringImageName] forState:UIControlStateNormal];
[imgScroll addSubview:btnGallery];
[_scrollView addSubview:imgScroll];
index++;
}
[_scrollView setContentSize:CGSizeMake(index*CGRectGetWidth(_scrollView.frame), CGRectGetHeight(_scrollView.frame))];
Assuming arrayGalleryImages consists of gallery image names.
I used button to add more action on tap.
Try code and manage scrollview delegate methods
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if([previouslyZoomedScroll zoomScale]!=1.0)
{
[previouslyZoomedScroll setZoomScale:1.0];
}
}