标签:libgdx android java robovm ios
@interface ClassName : ExtendedClassName<ImplementedInterfaceName>那么在java中就应该是:
@NativeClass public class GADBannerView extends UIView { }
@NativeClass public class GADBannerView extends NSObject { }
- (void)loadRequest:(GADRequest *)request;
@Method(selector = "loadRequest:")//必须和IOS里面的方法名一样 不然无法找到 public native void loadRequest(GADRequest request);//这里方法名可以任意写 但是参数必须一样如果有多个参数的方法呢?
- (void)setLocationWithLatitude:(CGFloat)latitude longitude:(CGFloat)longitude accuracy:(CGFloat)accuracyInMeters;
@Method(selector = "setLocationWithLatitude:longitude:accuracy:") public native void setLocation(float latitude, float longitude, float accuracyInMeters);
- (id)initWithAdSize:(GADAdSize)size;那么在java中实现:
@Method(selector = "initWithAdSize:") private native @Pointer long init(GADAdSize size);//构造方法需要值,因为GADAdSize实际上是long类型这里的方法写成私有的,因为不是任何人都可以调用的,所以还得写个java里的构造方法
public GADBannerView(GADAdSize size) { super((SkipInit)null); initObject(init(size)); }必须这样写,不然会被java调用两次
在IOS中有很多很简便的写法,可以让开发者少些很多代码
@property(nonatomic, copy) NSString *adUnitID;property这个意思是OC会自动实现getter和setter 不用手动实现,那么我们知道他的意思后就很好绑定了,和绑定方法一样一样的
@Property(selector = "adUnitID") public native String getAdUnitID (); @Property(selector = "setAdUnitID:") public native void setAdUnitID (String id);注意:并不是所有属性都有getter和setter的 有些只有getter比如:
@property(nonatomic, readonly) BOOL hasAutoRefreshed;还有一种写法在绑定的时候必须强引用,不然程序会报错:
@property(nonatomic, assign) NSObject<GADBannerViewDelegate> *delegate在绑定的时候必须这样写:
@Property(selector = "delegate") public native GADBannerViewDelegate getDelegate(); @Property(selector = "setDelegate:", strongRef = true) public native void setDelegate(GADBannerViewDelegate delegate);
typedef NS_ENUM(NSInteger, GADGender) { kGADGenderUnknown, ///< Unknown gender. kGADGenderMale, ///< Male gender. kGADGenderFemale ///< Female gender. };在java中这样写:
typedef enum { kGADGenderUnknown, ///< Unknown gender. kGADGenderMale, ///< Male gender. kGADGenderFemale ///< Female gender. } GADGender;
libgdx与Robovm绑定的一些方法,布布扣,bubuko.com
标签:libgdx android java robovm ios
原文地址:http://blog.csdn.net/qq634416025/article/details/35543715