MonoTouch - access to Obj-C Constants

2019-07-23 16:18发布

问题:

Many times I'll read Obj-C code and need the value to one of their constants present in one of the Obj-C header files.

For notifications, I've been able to find them in MonoTouch such as UIApplication.DidEnterBackgroundNotification.

Is there a standard way to get such values? I am needing to lookup UINavigationControllerHideShowBarDuration for an odd reason.

回答1:

UINavigationControllerHideShowBarDuration is a CGFloat, which MonoTouch maps to a .NET System.Single (float in C#).

You should be able to use MonoTouch.ObjCRuntime.Dlfcn.GetFloat method to retrieve the constant (it could change between versions and should not be embedded like a C# const) value at runtime. E.g.

IntPtr handle = Dlfcn.dlopen (Constants.UIKitLibrary, 0);
return Dlfcn.GetFloat (handle, "UINavigationControllerHideShowBarDuration");