黑科技:使用AI和機器學習將Android項目秒變IOS項目

最近看Github,發(fā)現(xiàn)了一個剛出爐的黑科技:利用人工智能(AI)和機器學習(ML)技術將現(xiàn)有Android源代碼轉(zhuǎn)換成iOS代碼。目前支持Android項目中的資產(chǎn)目錄文件和UI布局轉(zhuǎn)換,以及部分外部庫的轉(zhuǎn)換。有了這個神器,以后一個人就可以輕松搞定兩個平臺了,真是爽歪歪啊。。。。我根本不需要學習iOS了。。。


已支持的功能:

  1. Android的資產(chǎn)目錄 (如:jpgpng,.9圖等) => "Assets.xcassets"
  2. mipmap目錄的圖片資源 => “.appiconset”
  3. Color形式的xml => “.colorset”
  4. Shape形式的xml => PDF format in asset catalog
  5. Vector形式的xml文件 => Swift Code (CAShapeLayer)
  6. Animation形式的xml文件
  7. UI布局的xml文件 => storyboard file
  8. Java的POJO類 => Swift
  9. 外部的庫Glide的轉(zhuǎn)換

正在開發(fā)中的功能:

  1. 資源(Resource)xml文件
  2. Android SDK的類
  3. 更多的外部的庫,比如:GSON, Retrofit2, ButterKnife等。
  4. 矢量圖動畫(Vector Animation)xml資源

未來支持的功能:

  1. Android的Kotlin語言
  2. Android的JetPack
  3. Android的代碼編寫的布局 轉(zhuǎn)成 SwiftUI
  4. Lagacy .storyboard 轉(zhuǎn)成 SwiftUI
  5. 測試用例的生成

UI的轉(zhuǎn)換

目前支持CardView,Switch,ImageButton,ToggleButton這些控件類型的轉(zhuǎn)換。

部分效果圖如下:

CardView的屏幕截圖:

image

開關,ImageButton,ToggleButton的屏幕截圖:

image

Button的屏幕截圖:

image

TextView的屏幕截圖:

image

使用普通鍵盤的EditText的屏幕截圖:

image

帶電話撥號鍵盤的EditText的屏幕截圖:

image

布局的轉(zhuǎn)換

目前支持RelativeLayout,F(xiàn)rameLayout,LinearLayout (Nested),ConstraintLayout,TableLayout和ScrollView這些布局類型的轉(zhuǎn)換。另外只有部分布局屬性做了轉(zhuǎn)換,如下表所示:

Control Attributes
LinearLayout orientation, gravity, background, textAppearance
RelativeLayout layout_centerHorizontal, layout_centerVertical, layout_toLeftOf, layout_toRightOf, layout_above, layout_below, layout_alignParentTop, layout_alignParentBottom, layout_alignParentRight, layout_alignParentLeft
FrameLayout layout_marginTop, layout_gravity = right, left, right+bottom, left+bottom, center, center_horizontal, center_vertical, right+center_vertical, bottom+center_horizontal
ConstraintLayout Bottom_toBottomOf, Top_toTopOf, Top_toBottomOf, Left_toLeftOf, Start_toEndOf, Right_toRightOf, Baseline_toBaselineOf, Vertical_bias, Horizontal_bias
TableLayout TableLayout, TableRow, background, padding
ScrollView ScrollView, android.support.v4.widget.NestedScrollView, HorizontalScrollView, android:scrollbars

LinearLayout的屏幕截圖:

image

image

RelativeLayout的屏幕截圖:

image

image

FrameLayout的屏幕截圖:

image

image

ConstraintLayout的屏幕截圖(這個也做了移植,確實經(jīng)驚艷到我了):

image

image

TableLayout的屏幕截圖:

image

image

ScrollView的屏幕截圖:(gif圖內(nèi)容太大,做了壓縮)


資產(chǎn)目錄文件的轉(zhuǎn)換

這一部分內(nèi)容比較多,簡單的說就是把Android工程的res目錄的文件轉(zhuǎn)換成iOS工程的Assets.xcassets目錄的文件。

  • mipmap目錄的圖片資源:Android工程的mdpi,hdpi,xhdpi和xxhdpi的圖像資源被映射到iOS工程的1x,2x和3x圖像資源路徑里面。

  • 針對.9.png圖片文件:在catalog中為asset添加了切片(slicing )信息。

  • Vector圖片形式的xml被轉(zhuǎn)換成Storyboard上能夠使用的.pdf文件。

  • 向量圖像xml也被轉(zhuǎn)換成Swift代碼,并在VectorStore.swift中為每個vector文件添加一個靜態(tài)方法。

除此之外還支持.png,color形式的xml,Shape形式的xml,Animation形式的xml的轉(zhuǎn)換。


以下是使用截圖:

Android和iOS設備的顯示了各種資產(chǎn)的使用情況的屏幕截圖:

image

Android Studio布局編輯器:

image

Xcode Storyboard編輯器:

image

Android Studio Asset資源圖片:

image

Xcode Asset 面板:

image

Android Studio .9.PNG 圖片資源編輯器:

image

Xcode Asset面帶有從.9.png文件中提取的切片信息:

image

Vector矢量圖的轉(zhuǎn)換截圖對比:

image

Shape xml文件的對比:

image

動畫轉(zhuǎn)換的對比:

Android iOS

事實上效果是同步的,只是錄屏和操作步驟不一致的原因,看起來有些延遲。


外部庫Glide的轉(zhuǎn)換

支持的功能:

  • 從本地res文件夾加載drawable
  • 從URL加載圖片
  • 將圖片加載到UIImageView
  • 在下載過程中提供占位符圖片
  • 在圖片之間應用過渡:CrossFade,F(xiàn)lip
  • 支持圖片Transformation (變換)API:circleCrop(),centerCrop(),fitCenter(),centerInside()
  • 清除待處理的請求
  • RequestOptions類可在實例之間重用設置

待支持的API:

  • priority()
  • diskCacheStrategy()
  • asBitmap()
  • error()
  • fallback()
  • clearMemory()

使用截圖:

image

計算器App

這是一個移植的計算器項目。

使用截圖如下,還是挺酷選的呢,效果保持一致,操作也很流暢:

image

最后附上官網(wǎng)地址,有興趣的可以去看看。

官網(wǎng)地址:http://www.reflectcode.com/

Github: https://github.com/ReflectCode/

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容