W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
1.在 0.19 版本之前,Weex 使用 Yoga 排版引擎,可以通過訪問 WXComponent 的 cssNode 屬性獲取。例如:
self.cssNode->style.flex = 1.0;
float height = self.cssNode->style.dimensions[CSS_HEIGHT];
2.從 0.19 版本開始,Weex 使用自已的排版引擎,是 C++ 代碼。獲取 CSS 屬性可以從 WXComponent 的 styles 字典(NSDictionary)里獲取,也可以訪問 WXComponent 的 flexCssNode 屬性,其類型為 C++ 類 WeexCore::WXCoreLayoutNode。注意,需要源文件為 .mm 類型。
3.從 0.20 版本開始,iOS 接入 WeexCore,排版引擎也沉入 WeexCore層,并且 CSS 相關(guān)屬性不再上傳給 WXComponent 對象,WXComponent 對象的 styles 字典里只有非 CSS 樣式。我們的目的是上層 UI 組件只需要關(guān)心排版引擎生成的最終坐標即可,不需要關(guān)心前端標記的 CSS 屬性。如果仍然需要獲取 CSS 樣式,可以在 .mm 文件中直接訪問 flexCssNode,或通過 WXComponent+Layout.h 文件中提供的擴展方法。
/**
* @abstract Get css style value for key. The key should be of CSS standard form.
* This method is for convenience use in C/ObjC environment. And if you want to
* retrieve all style values or in C++, you could use flexCssNode directly.
*
* Thread usage:
* This method should be invoked in component thread by WXPerformBlockOnComponentThread.
* Note that all initWithRef methods of WXComponent and its subclasses are performed in
* component thread by default. Therefore you can call this method directly in initWithRef.
*
* Supported keys:
* width, height, min-width, min-height, max-width, max-height,
* margin-(left/right/top/bottom)
* padding-(left/right/top/bottom)
* border-(left/right/top/bottom)-width
* left, right, top, bottom
* flex-grow
*/
- (float)getCssStyleValueForKey:(NSString *)key;
// Other methods which should also be used in component thread.
- (WXCoreFlexDirection)getCssStyleFlexDirection;
- (WXCoreFlexWrap)getCssStyleFlexWrap;
- (WXCoreJustifyContent)getCssStyleJustifyContent;
- (WXCoreAlignItems)getCssStyleAlignItems;
- (WXCoreAlignSelf)getCssStyleAlignSelf;
- (WXCorePositionType)getCssStylePositionType;
- (WXCoreDirection)getCssDirection;
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: