在 MonoTouch 中缩放 UIScrollView [英] Zooming a UIScrollView in MonoTouch
问题描述
我正在尝试使用 MonoTouch 中的 UIScrollView 实现缩放功能,但我似乎无法让它工作.
I'm trying to implement zooming functionality using a UIScrollView in MonoTouch but I just can't seem to make it work.
我看过一些讨论设置委托的教程,但其中大部分是在 Obj-C 中,我无法转换为 C#.
I've looked at a few tutorials which talk about setting a Delegate but most of it is in Obj-C which I can't translate over to C#.
基本上,我在 Interface Builder 中有一个 UIScrollView,它有一个 UIImageView 作为子视图.
Basically, I have a UIScrollView in Interface Builder that has an UIImageView as a Subview.
我已将 UIScrollView 的 ContentSize 设置为图像的完整大小,并且还设置了最小/最大缩放比例.这是我的代码:
I've set the ContentSize of the UIScrollView to be the full size of the image and have also set a min/max zoom scale. Here's my code:
UIImage imgMap = new UIImage("img/map.png");
ivMap.Image = imgMap;
svMap.MinimumZoomScale = 1.0f;
svMap.MaximumZoomScale = 3.0f;
svMap.ContentSize = new System.Drawing.SizeF(ivMap.Frame.Width, ivMap.Frame.Height);
对我缺少的东西有什么想法吗?
Any ideas on what I'm missing?
编辑
我用@Geoff 提供的代码创建了一个新的 .xib 文件,但仍然没有运气,图像只是滚动但仍然没有缩放.
I've created a new .xib file with the code provided by @Geoff but still no luck, the image just scrolls but still doesn't zoom.
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
UIScrollView sv = new UIScrollView (thisView.Frame);
UIImageView iv = new UIImageView(UIImage.FromFile ("img/map.png"));
sv.AddSubview (iv);
sv.ContentSize = iv.Frame.Size;
sv.MinimumZoomScale = 1.0f;
sv.MaximumZoomScale = 3.0f;
vwMineral.AddSubview(sv);
}
推荐答案
尝试:
var sv = new UIScrollView (window.Frame);
var iv = new UIImageView (UIImage.FromFile ("pat.jpg"));
sv.AddSubview (iv);
sv.ContentSize = iv.Frame.Size;
sv.MinimumZoomScale = 1.0f;
sv.MaximumZoomScale = 3.0f;
sv.MultipleTouchEnabled = true;
sv.ViewForZoomingInScrollView = delegate(UIScrollView scrollView) {
return iv;
};
window.AddSubview (sv);
window.MakeKeyAndVisible ();
这篇关于在 MonoTouch 中缩放 UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!