zoukankan      html  css  js  c++  java
  • MonoTouch 绑定

    对绑定不了解的,请参考这篇文章 http://www.cnblogs.com/beginor/archive/2012/04/22/2465441.html

    本文主要讲述上文没有提到的

    1.构造函数

    在MonoTouch绑定中,构造函数名是固定的,都是 Constructor,返回类型:IntPtr.

    Obj-C 代码:

    -(id)initWithCenterViewController:(UIViewController *)centerViewController leftDrawerViewController:(UIViewController *)leftDrawerViewController rightDrawerViewController:(UIViewController *)rightDrawerViewController;

    绑定到MonoTouch:

    [Export ("initWithCenterViewController:leftDrawerViewController:rightDrawerViewController:")]
    IntPtr Constructor (UIViewController centerViewController, UIViewController leftDrawerViewController, UIViewController rightDrawerViewController);        

    2.代码块

    在Obj-C中,代码块很常用.它和.NET的Lamda表达式相似.可以绑定到委托(Delegate).

    Obj-C代码:

     -(void)setDrawerVisualStateBlock:(void(^)(MMDrawerController * drawerController, MMDrawerSide drawerSide, CGFloat percentVisible))drawerVisualStateBlock;

    绑定到MonoTouch时,分两部分:

    delegate void SetDrawerVisualStateBlockCallback (MMDrawerController  drawerController, MMDrawerSide drawerSide, float percentVisible);
    [Export ("setDrawerVisualStateBlock:")]
    void setDrawerVisualStateBlock (SetDrawerVisualStateBlockCallback drawerVisualStateBlock);

    在实际调用时:

    this.drawerController.setDrawerVisualStateBlock ((MMDrawerController  drawerController, MMDrawerSide drawerSide, float percentVisible)=>{
                Console.WriteLine("setDrawerVisualStateBlock");
    });

    3.委托(Delegate)

    这个比较直接,和.NET相似。

    Obj-C代码:

    @protocol FPPopoverControllerDelegate <NSObject>
    
    @optional
    - (void)popoverControllerDidDismissPopover:(FPPopoverController *)popoverController;
    - (void)presentedNewPopoverController:(FPPopoverController *)newPopoverController 
              shouldDismissVisiblePopover:(FPPopoverController*)visiblePopoverController;
    @end
    @property(nonatomic,assign) id<FPPopoverControllerDelegate> delegate;

    绑定到MonoTouch时,也分两部分:

    [Model, BaseType (typeof(NSObject))]
        interface FPPopoverControllerDelegate
        {
            [Export ("popoverControllerDidDismissPopover:")]
            void popoverControllerDidDismissPopover (FPPopoverController popoverController);
    
            [Export ("shouldDismissVisiblePopover:visiblePopoverController")]
            void shouldDismissVisiblePopover (FPPopoverController newPopoverController, FPPopoverController visiblePopoverController);
        }
            [Export("delegate")]
            NSObject WeakDelegate { get; set; }
    
            [Wrap("WeakDelegate")]
            FPPopoverControllerDelegate Delegate { get; set; }

    4.绑定类别(Category)

    这个似乎目前还没有实现.预计它以后的实现可能是这样:

    namespace XYOrigami
    {
      delegate void OrigamiAnimationCompleted (bool finished);
    
      [BaseType (typeof(UIView))]
      [Category]
      interface Origami{
    
          [Export ("showOrigamiTransitionWith:NumberOfFolds:Duration:Direction:completion:")]
          void ShowOrigamiTransition (UIView view, int folds, float duration, XYOrigamiDirection direction, OrigamiAnimationCompleted completed);
    
          [Export ("hideOrigamiTransitionWith:NumberOfFolds:Duration:Direction:completion:")]
          void HideOrigamiTransition (UIView view, int folds, float duration, XYOrigamiDirection direction, OrigamiAnimationCompleted completed);
      }
    }

    以上推测的依据是从  http://stackoverflow.com/questions/14961716/monotouch-binding-categories-using-category-attribute 而来.回答者 chrisntr 属于Xamarin 开发团队.

    欢迎到我的网站看看
  • 相关阅读:
    Building a Space Station POJ
    Networking POJ
    POJ 1251 Jungle Roads
    CodeForces
    CodeForces
    kuangbin专题 专题一 简单搜索 POJ 1426 Find The Multiple
    The Preliminary Contest for ICPC Asia Shenyang 2019 F. Honk's pool
    The Preliminary Contest for ICPC Asia Shenyang 2019 H. Texas hold'em Poker
    The Preliminary Contest for ICPC Asia Xuzhou 2019 E. XKC's basketball team
    robotparser (File Formats) – Python 中文开发手册
  • 原文地址:https://www.cnblogs.com/Caiyinsoft/p/3466102.html
Copyright © 2011-2022 走看看