Xamarin绑定类别返回错误:无法在静态类中声明实例成员

时间:2014-02-19 03:37:32

标签: ios objective-c binding xamarin

我尝试将ReFrostedViewController绑定到c#。我使用Objective Sharpie生成接口。但是当我使用Xamarin编译它时,它会返回错误。

 /REFrostedViewController_UIViewController.g.cs(10,10): Error CS0708: `REFrostedMenu.REFrostedViewController_UIViewController.__mt_FrostedViewController_var': cannot declare instance members in a static class (CS0708) (REFrostedBinding)

这是我的代码:

[Export ("frostedViewController", ArgumentSemantic.Retain)]
REFrostedViewController FrostedViewController { get; }

我改变了如下:

[Export ("frostedViewController", ArgumentSemantic.Retain)]
REFrostedViewController FrostedViewController()

它可以编译,但我无法从UIViewController获取它。

REFrostedViewController reFrost = base.FrostedViewController();

它返回错误:

/MainViewController.cs(43,43): Error CS0117: `MonoTouch.UIKit.UIViewController' does not contain a definition for `FrostedViewController' (CS0117) (iOS)

更新: 这是完整的代码

using System;
using System.Drawing;
using MonoTouch.ObjCRuntime;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace REFrostedMenu
{
[BaseType (typeof (UIViewController))]
public partial interface REFrostedContainerViewController {

    [Export ("screenshotImage", ArgumentSemantic.Retain)]
    UIImage ScreenshotImage { get; set; }

    [Export ("frostedViewController", ArgumentSemantic.Assign)]
    REFrostedViewController FrostedViewController { get; set; }

    [Export ("animateApperance")]
    bool AnimateApperance { get; set; }

    [Export ("containerView", ArgumentSemantic.Retain)]
    UIView ContainerView { get; }

    [Export ("panGestureRecognized:")]
    void PanGestureRecognized (UIPanGestureRecognizer recognizer);

    [Export ("hide")]
    void Hide ();

    [Export ("resizeToSize:")]
    void ResizeToSize (SizeF size);

//      [Export ("hideWithCompletionHandler:")]
//      void HideWithCompletionHandler(HideCompletionHandler handler);

    [Export ("refreshBackgroundImage")]
    void RefreshBackgroundImage ();
}

[BaseType (typeof (UIViewController))]
public partial interface REFrostedViewController {

    [Export ("panGestureRecognizer", ArgumentSemantic.Retain)]
    UIPanGestureRecognizer PanGestureRecognizer { get; }

    [Export ("panGestureEnabled")]
    bool PanGestureEnabled { get; set; }

//      [Export ("direction")]
//      REFrostedViewControllerDirection Direction { get; set; }

    [Export ("backgroundFadeAmount")]
    float BackgroundFadeAmount { get; set; }

    [Export ("blurTintColor", ArgumentSemantic.Retain)]
    UIColor BlurTintColor { get; set; }

    [Export ("blurRadius")]
    float BlurRadius { get; set; }

    [Export ("blurSaturationDeltaFactor")]
    float BlurSaturationDeltaFactor { get; set; }

    [Export ("animationDuration")]
    double AnimationDuration { get; set; }

    [Export ("limitMenuViewSize")]
    bool LimitMenuViewSize { get; set; }

    [Export ("menuViewSize", ArgumentSemantic.Assign)]
    SizeF MenuViewSize { get; set; }

    [Export ("liveBlur")]
    bool LiveBlur { get; set; }

//      [Export ("liveBlurBackgroundStyle")]
//      REFrostedViewControllerLiveBackgroundStyle LiveBlurBackgroundStyle { get;    set; }

//      [Export ("delegate", ArgumentSemantic.Assign)]
//      REFrostedViewControllerDelegate Delegate { get; set; }

    [Export ("contentViewController", ArgumentSemantic.Retain)]
    UIViewController ContentViewController { get; set; }

    [Export ("menuViewController", ArgumentSemantic.Retain)]
    UIViewController MenuViewController { get; set; }

    [Export ("initWithContentViewController:menuViewController:")]
    IntPtr Constructor (UIViewController contentViewController, UIViewController menuViewController);

    [Export ("presentMenuViewController")]
    void PresentMenuViewController ();

    [Export ("hideMenuViewController")]
    void HideMenuViewController ();

    [Export ("resizeMenuViewControllerToSize:")]
    void ResizeMenuViewControllerToSize (SizeF size);

//      [Export ("hideMenuViewControllerWithCompletionHandler:")]
//      void HideMenuViewControllerWithCompletionHandler (HideMenuViewControllerCompletionHandler handler);

    [Export ("panGestureRecognized:")]
    void PanGestureRecognized (UIPanGestureRecognizer recognizer);
}

[BaseType (typeof (NSObject))]
[Model]
public partial interface REFrostedViewControllerDelegate {

    [Export ("frostedViewController:willAnimateRotationToInterfaceOrientation:duration:")]
    void WillAnimateRotationToInterfaceOrientation (REFrostedViewController frostedViewController, UIInterfaceOrientation toInterfaceOrientation, double duration);

    [Export ("frostedViewController:didRecognizePanGesture:")]
    void DidRecognizePanGesture (REFrostedViewController frostedViewController, UIPanGestureRecognizer recognizer);

    [Export ("frostedViewController:willShowMenuViewController:")]
    void WillShowMenuViewController (REFrostedViewController frostedViewController, UIViewController menuViewController);

    [Export ("frostedViewController:didShowMenuViewController:")]
    void DidShowMenuViewController (REFrostedViewController frostedViewController, UIViewController menuViewController);

    [Export ("frostedViewController:willHideMenuViewController:")]
    void WillHideMenuViewController (REFrostedViewController frostedViewController, UIViewController menuViewController);

    [Export ("frostedViewController:didHideMenuViewController:")]
    void DidHideMenuViewController (REFrostedViewController frostedViewController, UIViewController menuViewController);
}

[BaseType (typeof (UIImage))]
[Category]
public partial interface REFrostedViewController_UIImage {

    [Export ("re_applyBlurWithRadius:tintColor:saturationDeltaFactor:maskImage:")]
    UIImage Re_applyBlurWithRadius (float blurRadius, UIColor tintColor, float saturationDeltaFactor, UIImage maskImage);

    [Export ("re_screenshot")]
    UIImage Re_screenshot ();
}

[BaseType (typeof (UIViewController))]
[Category]
public partial interface REFrostedViewController_UIViewController {

    [Export ("frostedViewController", ArgumentSemantic.Retain)]
    REFrostedViewController FrostedViewController();

    [Export ("re_displayController:frame:")]
    void Re_displayController (UIViewController controller, RectangleF frame);

    [Export ("re_hideController:")]
    void Re_hideController (UIViewController controller);
}
}

请帮助我,我非常感谢!

1 个答案:

答案 0 :(得分:4)

我在Github上创建了一个绑定项目和示例作为fork:https://github.com/therealjohn/REFrostedViewController

“无法在静态类中声明实例成员”错误是因为

[Export ("frostedViewController", ArgumentSemantic.Retain)]
REFrostedViewController FrostedViewController { get; }

尝试在类别中创建属性,这基本上是一种扩展方法。没有“扩展”C#属性,所以你改变一个方法“修复”那个错误。

我不确定你有什么其他问题,但我做的项目应该适合你。

享受!