1

我试图让我的代码以编程方式放大到大图的一小块区域。我稍后会添加点击代码,但现在我只想看看它是否有效。

这段代码中的 zoomToRect 完全没有任何作用,我根本不明白为什么。当我构建它时,图像就位于原点 0,0 处。

我试过使用:

setContentOffset 和 scrollRectToVisible 两者都工作正常 - 图像移动到指定的坐标。但这些都不是我想要的,因为我需要移动和缩放图像,而不仅仅是移动它。

但是 zoomToRect 完全拒绝做任何事情。我现在已经阅读了大约 50 页的示例和教程,但该死的东西没有用。我把头发扯下来不知道为什么。显然,我错过了一些非常基本或重要的观点。

UIImage *myFirstImage = [UIImage imageNamed:@"manga_page.jpg"];

UIImageView *myFirstImageView = [[UIImageView alloc] initWithImage:myFirstImage];

[myFirstImageView setFrame:CGRectMake(0, 0, myFirstImage.size.width, myFirstImage.size.height)];


UIScrollView *myFirstScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

[myFirstScrollView setContentSize:CGSizeMake(myFirstImage.size.width, myFirstImage.size.height)];

[myFirstScrollView addSubview:myFirstImageView];

[self.view addSubview:myFirstScrollView];

[myFirstScrollView zoomToRect:CGRectMake(300, 300, 300, 300) animated:YES];
4

2 回答 2

2

问题是我没有定义缩放代表 - 请参见 viewForZoomingInScrollView (页面底部):

https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollviewdelegate_protocol/Reference/UIScrollViewDelegate.html#//apple_ref/occ/intfm/UIScrollViewDelegate/viewForZoomingInScrollView

当我切换到 Xamarin 框架时,我在 Objective C 中没有代码片段。但是 C# 解决方案如下:

scrollView.ViewForZoomingInScrollView = delegate (UIScrollView sv) { return imageView; };

其中 imageView 是 UIImageView 包含要滚动的图像。

于 2013-11-07T07:57:46.890 回答
0

设置 UIScrollView 的 maximumZoomScale 和 minimumZoomScale 属性。

于 2012-08-04T06:07:03.997 回答