Anu*_*nuj 8 objective-c xamarin.ios
我正在尝试使用btouch将WEPopover绑定到MonoTouch.它使用UIBarButtonItem类别实现来扩展它的功能,以包括弹出窗口的表示.
@interface UIBarButtonItem(WEPopover)
- (CGRect)frameInView:(UIView *)v;
- (UIView *)superview;
@end
Run Code Online (Sandbox Code Playgroud)
我如何使用btouch接口定义将其绑定到MonoTouch?
我的旧答案错过了使用类别的事实.评论中指出了这一点,并且与Xamarin文档的链接确实涵盖了这一点.引用:
在Objective-C中,可以使用新方法扩展类,这与C#的扩展方法类似.当存在这些方法之一时,您可以使用该
[Target]属性将方法的第一个参数标记为Objective-C消息的接收者.例如,在MonoTouch中,我们绑定了
NSString在UIKit作为方法导入时 定义的扩展方法UIView,如下所示:
[BaseType (typeof (UIResponder))]
interface UIView {
[Bind ("drawAtPoint:withFont:")]
SizeF DrawString ([Target] string str, PointF point, UIFont font);
}
Run Code Online (Sandbox Code Playgroud)
来自:http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types#Binding_Class_Extensions
以上示例是MonoTouch用于绑定的内容drawAtPoint:withFont:,它是NSString UIKit Additions的一部分
这是上述内容的快速(且未经测试)定义:
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Drawing;
namespace MonoTouch.Popover {
[BaseType (typeof (UIBarButtonItem))]
public interface WEPopover {
[Export ("frameInView")]
RectangleF FrameInView (UIView view);
[Export ("superView")]
UIView SuperView { get; }
}
}
Run Code Online (Sandbox Code Playgroud)
然后使用btouch工具将定义编译为可在 MonoTouch 中使用的 .dll,例如
imac:tmp sebastienpouliot$ /Developer/MonoTouch/usr/bin/btouch we.cs
imac:tmp sebastienpouliot$ ls -l we.dll
-rwxr-xr-x 1 sebastienpouliot staff 5632 28 Aug 10:23 we.dll
Run Code Online (Sandbox Code Playgroud)
我建议您阅读有关如何绑定现有 ObjectiveC 库的现有文档。该文档可从以下位置获取:http://ios.xamarin.com/Documentation/Binding_New_Objective-C_Types
| 归档时间: |
|
| 查看次数: |
1071 次 |
| 最近记录: |