gpt4 book ai didi

ios - ScrollView 在点击它时向上移动

转载 作者:行者123 更新时间:2023-11-29 10:35:37 25 4
gpt4 key购买 nike

我是 iPhone 开发新手。我在 UIScrollView(zoomscrollView) 中包含的 UIImageView 中有一个图像,它包含在另一个 UIScrollView(scrollViewgalery) 中。

我的问题是,在触摸第一个 ScrollView (即 zoomScrollview)时,它会向上移动。

最佳答案

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];
}
}

关于ios - ScrollView 在点击它时向上移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27286921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com