在MonoTouch中实现Delegate Callback方法

时间:2012-09-10 10:17:38

标签: c# delegates xamarin.ios

  

可能重复:
  Zooming a UIScrollView in MonoTouch

我需要在我的应用程序中实现这个objective-c委托回调:

-(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll {
  return imageView;
}

但是,我使用MonoTouch开发我的应用程序,如何在MonoTouch中实现代理? (我知道我可能没有使用关于在MonoTouch中实施代表的正确术语,请告知)。

这是我需要委托回调的代码(我需要在scrollview中的imageview可以缩放):

public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        Loader loader = new Loader("/Users/jacknutkins/Documents/ARCSDev");
        loader.LoadChart("2");
        CGBitmapContext context = loader.GetHiResImage(loader.PaletteFile.RGBPaletteDay);
        UIImage image = UIImage.FromImage(context.ToImage());
        this.View.BackgroundColor = UIColor.Red;
        RectangleF rect = new RectangleF(0.0f, 0.0f, image.Size.Width, image.Size.Height);
        //RectangleF rect = new RectangleF(scrollView.Frame.Location, scrollView.Frame.Size);
        UIImageView imageView = new UIImageView(rect);
        imageView.Image = image;
        scrollView.ContentSize = image.Size;
        scrollView.AddSubview(imageView);
        scrollView.ClipsToBounds = true;
        scrollView.SetZoomScale(0.5f, true);
        Console.WriteLine("View Did Load Done.");
        // Perform any additional setup after loading the view, typically from a nib.
    }

Tysin

1 个答案:

答案 0 :(得分:3)

您只需向ViewForZoomingInScrollView事件添加事件处理程序:

scrollView.ViewForZoomingInScrollView += (UIScrollView sv) => 
{
    return null;
};