如何获得“前线” uiimageview 来自 uiscrollviews?
我在其他地方看到过这个问题...但没有有效的答案...
我有一个水平滚动的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以跟踪您所在的位置:
这让我知道当用户滚动浏览内容时我所在的内容“页面”。
You can track where you are in:
That lets me know what "page" of content I'm on as the user scrolls through it.
您可以子类化 UIImageView 类并实现触摸方法。
You could subclass the UIImageView class and implement the touch methods.