我在演练中仔细遵循了每个步骤:绑定 iOS Objective-C 库
TestBindings项目的构建结果是成功的。
但是,我得到了空的命名空间引用。
我的开发环境设置是:
- 视窗 10 专业版 1909
- Visual Studio 2019 专业版 16.6.0
- macOS Catalina 10.15.5
- XCode 版本 11.4.1
项目结构是:
每个源代码是:
ApiDefinition.cs
using CoreGraphics;
using Foundation;
using ObjCRuntime;
using UIKit;
namespace TestBindings
{
// @interface InfColorBarView : UIView
[BaseType(typeof(UIView))]
interface InfColorBarView
{
}
// @interface InfColorBarPicker : UIControl
[BaseType(typeof(UIControl))]
interface InfColorBarPicker
{
// @property (nonatomic) float value;
[Export("value")]
float Value { get; set; }
}
// @interface InfColorIndicatorView : UIView
[BaseType(typeof(UIView))]
interface InfColorIndicatorView
{
// @property (nonatomic) UIColor * color;
[Export("color", ArgumentSemantic.Assign)]
UIColor Color { get; set; }
}
// @interface InfColorPickerController : UIViewController
[BaseType(typeof(UIViewController))]
interface InfColorPickerController
{
// +(InfColorPickerController *)colorPickerViewController;
[Static]
[Export("colorPickerViewController")]
// [Verify(MethodToProperty)]
InfColorPickerController ColorPickerViewController { get; }
// +(CGSize)idealSizeForViewInPopover;
[Static]
[Export("idealSizeForViewInPopover")]
// [Verify(MethodToProperty)]
CGSize IdealSizeForViewInPopover { get; }
// -(void)presentModallyOverViewController:(UIViewController *)controller;
[Export("presentModallyOverViewController:")]
void PresentModallyOverViewController(UIViewController controller);
// @property (nonatomic) UIColor * sourceColor;
[Export("sourceColor", ArgumentSemantic.Assign)]
UIColor SourceColor { get; set; }
// @property (nonatomic) UIColor * resultColor;
[Export("resultColor", ArgumentSemantic.Assign)]
UIColor ResultColor { get; set; }
[Wrap("WeakDelegate")]
InfColorPickerControllerDelegate Delegate { get; set; }
// @property (nonatomic, weak) id<InfColorPickerControllerDelegate> delegate;
[NullAllowed, Export("delegate", ArgumentSemantic.Weak)]
NSObject WeakDelegate { get; set; }
}
// @protocol InfColorPickerControllerDelegate
[BaseType(typeof(NSObject))]
[Model]
interface InfColorPickerControllerDelegate
{
// @optional -(void)colorPickerControllerDidFinish:(InfColorPickerController *)controller;
[Export("colorPickerControllerDidFinish:")]
void ColorPickerControllerDidFinish(InfColorPickerController controller);
// @optional -(void)colorPickerControllerDidChangeColor:(InfColorPickerController *)controller;
[Export("colorPickerControllerDidChangeColor:")]
void ColorPickerControllerDidChangeColor(InfColorPickerController controller);
}
// @interface InfColorPickerNavigationController : UINavigationController
[BaseType(typeof(UINavigationController))]
interface InfColorPickerNavigationController
{
}
// @interface InfColorSquareView : UIImageView
[BaseType(typeof(UIImageView))]
interface InfColorSquareView
{
// @property (nonatomic) float hue;
[Export("hue")]
float Hue { get; set; }
}
// @interface InfColorSquarePicker : UIControl
[BaseType(typeof(UIControl))]
interface InfColorSquarePicker
{
// @property (nonatomic) float hue;
[Export("hue")]
float Hue { get; set; }
// @property (nonatomic) CGPoint value;
[Export("value", ArgumentSemantic.Assign)]
CGPoint Value { get; set; }
}
// @interface InfSourceColorView : UIControl
[BaseType(typeof(UIControl))]
interface InfSourceColorView
{
// @property (nonatomic) BOOL trackingInside;
[Export("trackingInside")]
bool TrackingInside { get; set; }
}
// @interface TestBindings : NSObject
[BaseType(typeof(NSObject))]
interface TestBindings
{
}
}
结构体.cs
using System;
using System.Runtime.InteropServices;
using CoreGraphics;
namespace TestBindings
{
static class CFunctions
{
// extern float pin (float minValue, float value, float maxValue);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern float pin(float minValue, float value, float maxValue);
// extern void HSVtoRGB (float h, float s, float v, float *r, float *g, float *b);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern unsafe void HSVtoRGB(float h, float s, float v, float* r, float* g, float* b);
// extern void RGBToHSV (float r, float g, float b, float *h, float *s, float *v, BOOL preserveHS);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern unsafe void RGBToHSV(float r, float g, float b, float* h, float* s, float* v, bool preserveHS);
// extern CGImageRef createSaturationBrightnessSquareContentImageWithHue (float hue);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern unsafe CGImage createSaturationBrightnessSquareContentImageWithHue(float hue);
// extern CGImageRef createHSVBarContentImage (InfComponentIndex barComponentIndex, float *hsv);
[DllImport("__Internal")]
// [Verify(PlatformInvoke)]
static extern unsafe CGImage createHSVBarContentImage(InfComponentIndex barComponentIndex, float[] hsv);
}
public enum InfComponentIndex : uint
{
Hue = 0,
Saturation = 1,
Brightness = 2
}
}
libTestBindings.linkwith.cs
using System;
using ObjCRuntime;
[assembly: LinkWith ("libTestBindings.a", LinkTarget.ArmV7, SmartLink = true, ForceLoad = true)]
libTestBindings.a
苹果系统