如何获得“前线” uiimageview 来自 uiscrollviews?

发布于 2024-11-08 22:09:16 字数 1581 浏览 0 评论 0原文

我在其他地方看到过这个问题...但没有有效的答案...

我有一个水平滚动的 UIScrollView 。我其中有 3 张照片...即: UIScrollView 的子视图保存 UIImageViews 如下:(在这种情况下,UIScrollView 的所有子视图都显示 path_to_file.png...以便于询问这个问题)

NSString *filepath = @"path_to_file.png";
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height)];
scroll.delegate = self;
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 3;
int maxImageWidth = 0;
for (int i = 0; i < numberOfViews; i++)  
{
    CGFloat yOrigin = i * self.view.frame.size.width;
    UIImage *imgWord = [[UIImage alloc] initWithContentsOfFile:filePath];
    UIImageView *imgWordView = [[UIImageView alloc] initWithImage:imgWord];
    [imgWord release];
    imgWordView.center = CGPointMake ((cell.contentView.frame.size.width/2) + yOrigin,imgWord.size.height/2);
    if (cell.contentView.frame.size.width > maxImageWidth)  {
    maxImageWidth = cell.contentView.frame.size.width;
    }
    [scroll addSubview:imgWordView];
    [imgWordView release];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
[cell.contentView addSubview:scroll]; 
[scroll release];

有了上面的代码片段,我遇到了我需要的事实:

-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return image;
}

在 UIScrollView 中缩放 UIImageView。我如何找出 UIScrollview 中正在显示的 UIImageView,以便我可以依次访问该 UIImageView 来获取 UIImage,以便在 viewForZoomingInScrollView 中返回它?

请解释一下,因为我不明白我们如何自己跟踪“显示”子视图...

谢谢!

I have seen this question asked in other places...but no valid answers...

I have a UIScrollView that scrolls horizontally. I have 3 photos in them...ie: subviews of the UIScrollView hold UIImageViews as below: (in this case, all the subviews of the UIScrollView are showing path_to_file.png... for ease of asking this question)

NSString *filepath = @"path_to_file.png";
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height)];
scroll.delegate = self;
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 3;
int maxImageWidth = 0;
for (int i = 0; i < numberOfViews; i++)  
{
    CGFloat yOrigin = i * self.view.frame.size.width;
    UIImage *imgWord = [[UIImage alloc] initWithContentsOfFile:filePath];
    UIImageView *imgWordView = [[UIImageView alloc] initWithImage:imgWord];
    [imgWord release];
    imgWordView.center = CGPointMake ((cell.contentView.frame.size.width/2) + yOrigin,imgWord.size.height/2);
    if (cell.contentView.frame.size.width > maxImageWidth)  {
    maxImageWidth = cell.contentView.frame.size.width;
    }
    [scroll addSubview:imgWordView];
    [imgWordView release];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
[cell.contentView addSubview:scroll]; 
[scroll release];

Having the above code snippet, I run across the fact that I need:

-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return image;
}

to zoom my UIImageView in the UIScrollView. How do i find out which UIImageView is showing in the UIScrollview so i can in turn access that UIImageView to get the UIImage in order to return it in viewForZoomingInScrollView?

Please explain this as I do not see how we are to track the 'displayed' subview ourselves...

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

櫻之舞 2024-11-15 22:09:16

我如何找出 UIScrollview 中显示的 UIImageView,以便我可以依次访问该 UIImageView 来获取 UIImage,以便将其返回到 viewForZoomingInScrollView 中?

您可以跟踪您所在的位置:

- (void) scrollViewDidScroll:(UIScrollView *)scrollView


CGFloat pageWidth = ScrollView.frame.size.width;
page = floor((self.ScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; 

这让我知道当用户滚动浏览内容时我所在的内容“页面”。

How do i find out which UIImageView is showing in the UIScrollview so i can in turn access that UIImageView to get the UIImage in order to return it in viewForZoomingInScrollView?

You can track where you are in:

- (void) scrollViewDidScroll:(UIScrollView *)scrollView


CGFloat pageWidth = ScrollView.frame.size.width;
page = floor((self.ScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; 

That lets me know what "page" of content I'm on as the user scrolls through it.

世俗缘 2024-11-15 22:09:16

您可以子类化 UIImageView 类并实现触摸方法。

You could subclass the UIImageView class and implement the touch methods.

讽刺将军 2024-11-15 22:09:16
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int page_ = (int)round(scrollView.contentOffset.x /scrollView.frame.size.width);
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int page_ = (int)round(scrollView.contentOffset.x /scrollView.frame.size.width);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文