Skip to content
zhenglibao edited this page Sep 11, 2019 · 22 revisions

为什么xml已经修改,但是界面还是旧的?

这种情况会发生在release打包的情况下,原因是为了加快产品模式下加载界面的速度,在产品模式下(release下)是有二进制缓存的,并不是每次都去解析xml。解决方法:重新打包前修改工程的build号

在framework组件中使用flexlib找不到xml怎么解决?

默认情况下flexlib会在mainBundle中去加载xml,你可以重写owner的bundleForRes方法来指定从哪个bundle加载xml。另外你可以通过FlexSetLoadFunc设置自定义的加载方法,缺点是该方法是一个全局方法,需要考虑的情况会比较多。

编译时报错找不到符号std::basic_string等怎么办?

需要添加c++的库,在build phase下添加libc++.tbd

Why the frame of view is CRect(0,0,0,0) ?

xml的视图树在加载后所有view的frame都是CRectZero, 只有在系统调用了FlexRootView::layoutSubViews方法后frame才会更新成真正的值,你可以通过监听FLEXDIDLAYOUT来获得完成布局的通知

不要使用FlexRootView::onDidLayout,该block用于内部用途

或者简单的办法,首先调用根视图的 layoutIfNeeded,然后再获取frame 对于FlexCustomBaseView,调用sizeToFit方法来完成布局

I make pod install, but FlexLib is very old version.

You should update your pod repository:

pod update FlexLib

Cmd+R or Cmd+D not work

Please check your simulator setting: goto "Hardware -> Keyboard", checked "Use the Same Keyboard as macOS" and "Connect Hardware keyboard" If still not work, please restart your simulator and Xcode.

Cmd+R shortcut works, but ui not refresh

Please check your simulator network, make sure your mac http server is accessible on safari.

Possible reasons & solutions:

  • proxy or vpn has been set, you need to close it.
  • In iOS system settings -> Developer -> Allow HTTP Services
  • App http access was not allowed by default. You must turn on it.
  • Maybe iOS simulator need restart.
  • Turn off wifi, then turn on it.

How to localize layout file

In layout file, only view attribute support multi-language. For the attribute value, you can use @ to reference the string in Localizable.strings. Like

    <UILabel attr="text:@title"/>

Notice: if the first character is @, you should use @@ instead of @. Like

    <UILabel attr="text:@@title"/>

The label text will be @title, not the string in Localizable.strings.

By default, the framework will fetch the localizable string from mainBundle. You can implement bundleForStrings in owner to change it.

Should I write a custom base class from FlexBaseVC for my project?

Yes, I recommend it. Although FlexBaseVC works well in most case, you may need some custom behaviour like different safe area for iPhoneX, custom keyboard toolbar etc.

Can I use my custom view class in xml layout file?

Of course you can. But your custom view class must conform with the following rules:

  • All the initialization must be done in init method. Any other init function like initWith... will not be called.
  • You can extend view attributes with FLEXSET macro, then you can set the attribute in xml file. Then you can use your custom view.

Is there a way to call the specific initWith... method during for the view in xml?

Yes. You should override the createView:Name: method in the owner like ViewCtronller, TabelCell,...

How to scale font size for different screen?

  • Call FlexSetScale(factor,offset) to set factor and offset
  • In layout file, change number value with * prefix. like:
  <UILabel attr="fontSize: *16"/>

The final font size will be 16*factor+offset

  • If your string should start with *, you should use ** instead of *. Thanks for 青柠.
  • Both view attribute and layout attribute support to scale the number.

The source attribute of UIImageView support network image?

No. Support network image will need network framework. It will make this framework overstaffed. You can use FLEXSET macro to extend the attribute of UIImageView if you really need it.

In the view controller the frame of the top view in xml is wrong.

First, FlexLib expect the view of view controller is full screen. Then FlexBaseVC adjust the frame of FlexRootView by getSafeArea to the right region. If the view of view controller is not full screen, you will need to override the getSafeArea to adjust the frame of FlexRootView. Please see the wiki to get more information.

Clone this wiki locally