libgdx與Robovm綁定的一些方法

來源:互聯網
上載者:User

標籤:libgdx   android   java   robovm   ios   

1.在IOS中綁定類

@interface ClassName : ExtendedClassName<ImplementedInterfaceName>
那麼在java中就應該是:

@NativeClasspublic class GADBannerView extends UIView {}

這裡一般形式是:

@NativeClasspublic class GADBannerView extends NSObject {}

2.在IOS中Binder 方法

- (void)loadRequest:(GADRequest *)request;

在java中

@Method(selector = "loadRequest:")//必須和IOS裡面的方法名一樣 不然無法找到public native void loadRequest(GADRequest request);//這裡方法名可以任意寫 但是參數必須一樣
如果有多個參數的方法呢?

- (void)setLocationWithLatitude:(CGFloat)latitude longitude:(CGFloat)longitude accuracy:(CGFloat)accuracyInMeters;

在java寫法是這樣的:

@Method(selector = "setLocationWithLatitude:longitude:accuracy:")public native void setLocation(float latitude, float longitude, float accuracyInMeters);

3.在IOS中綁定構造方法

- (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調用兩次

4.在IOS中綁定成員變數

在IOS中有很多很簡便的寫法,可以讓開發人員少些很多代碼

@property(nonatomic, copy) NSString *adUnitID;
property這個意思是OC會自動實現getter和setter 不用手動實現,那麼我們知道他的意思後就很好綁定了,和Binder 方法一樣一樣的

@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);


5.在IOS中綁定枚舉類型

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;

以上寫法精簡自:https://github.com/BlueRiverInteractive/robovm-ios-bindings



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.