放大MonoTouch的一个UIScrollView

放大MonoTouch的一个UIScrollView

本文介绍了放大MonoTouch的一个UIScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用MonoTouch的一个UIScrollView实现缩放功能,但我似乎无法使它发挥作用。



我已经看了几其中谈论设置一个委托,但大部分是在OBJ - C的教程,我不能转换到C#。



基本上,我有在Interface Builder一个UIScrollView有一个的UIImageView作为子视图。



我已经设置的UIScrollView的ContentSize为图像的完整大小,并还设置了最小/最大变焦倍数。这里是我的代码:

 的UIImage imgMap =新的UIImage(IMG / map.png); 
ivMap.Image = imgMap;
svMap.MinimumZoomScale = 1.0F;
svMap.MaximumZoomScale = 3.0F;
svMap.ContentSize =新System.Drawing.SizeF(ivMap.Frame.Width,ivMap.Frame.Height);

这是我缺少的是什么我任何想法?



修改



我创建的代码创建一个新的.xib文件通过@Geoff但仍没有运气,只是春联但仍然没有放大图像提供。

 公共覆盖无效viewDidLoad中() 
{
base.ViewDidLoad();

UIScrollView的SV =新的UIScrollView(thisView.Frame);
的UIImageView IV =新的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 =新的UIScrollView(window.Frame); 
变种IV =新的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 =委托(滚动视图的UIScrollView){
返回IV;
};

window.AddSubview(SV);
window.MakeKeyAndVisible();


I'm trying to implement zooming functionality using a UIScrollView in MonoTouch but I just can't seem to make it work.

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#.

Basically, I have a UIScrollView in Interface Builder that has an UIImageView as a Subview.

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?

EDIT

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);
}
解决方案

Try:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:51