1

我试图让 UIScrollView 在我的 Monotouch 应用程序中工作。无论我将 SetZoomScale() 设置为什么,它总是忽略我的起始比率。理想情况下,我希望它在启动时进行 0.5f 缩放。

theGraphScrollView = new UIScrollView(theRect);  // Half of the screen height, full width of screen
this.View.AddSubview(theGraphScrollView);

UIImageView imageView = new UIImageView(thePhotoSource.LoadPhotoFromFile("IMG_0_17.JPG"));
theGraphScrollView.ContentSize = imageView.Image.Size;  // This is much bigger than the screen width and height.
theGraphScrollView.MaximumZoomScale = 3f;
theGraphScrollView.MinimumZoomScale = 0.5f;
theGraphScrollView.SetZoomScale(0.5f, true);
theGraphScrollView.AddSubview(imageView);
theGraphScrollView.ViewForZoomingInScrollView += (UIScrollView sv) => { return imageView;   };

谁能告诉我哪里出错了。

非常感谢。

4

2 回答 2

3

你需要SetZoomScale()在最后。

ViewForZoomingInScrollView应在更改缩放之前连接。

于 2012-09-18T19:56:01.493 回答
1

通过调用SetZoomScale,UIScrollView尝试为视图设置动画,但您既没有添加图像,也没有设置代理来通知theGraphScrollView要缩放的视图。

移动SetZoomScale到最后,您将被设置。如果这是在您的 中ViewDidLoad,您可能还需要设置第二个参数SetZoomScaletofalse以防止图表在您第一次加载视图时生成动画。当然,这是一个偏好问题。

于 2012-09-18T19:58:26.393 回答