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 开发团队.

 

 

 

 

转载于:https://www.cnblogs.com/Caiyinsoft/p/3466102.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值