-
Notifications
You must be signed in to change notification settings - Fork 257
Hot preview
由于苹果审核问题,最新版默认将不接入在线预览功能,想使用的话需要独立接入,如 pod 'FlexLib/preview'
- call FlexRestorePreviewSetting when app start.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
FlexRestorePreviewSetting();
// any other initiation ...
return YES;
}
This function will do nothing for product version.
- start HTTP Server on your mac.
Enter your project directory in terminal, then
python -m SimpleHTTPServer 8000 #for python 2.x
python -m http.server 8000 #for python 3.x
- set preview base url
Open preview setting page, you can use one of the following ways:
- press Command+D when any sub class of FlexBaseVC appear. This is simplest way but only available in DEBUG mode.
- call FlexSetPreviewVC::presentInVC in your app to open this page.
Then you can set the preview base url.
There are three ways to do it:
-
press Control+E when sub class of FlexBaseVC appear. This will open 'Online Flex Explorer', then you can navigate and view your xml layout by HTTP Protocol. You can also call FlexHttpVC::presentInVC to make it available.
-
press Command+R when your view controller appears. This will reload your view controller layout but not call your any initiation methods like viewDidLoad.
-
In preview setting page, turn on 'Online load resource'. Then all the layout will be loaded by HTTP Protocol. You can reopen the current page to refresh it. This will works well even your page need some network request.
Notice: All the shortcuts should be pressed on simulator when view controller is shown, not in XCode. The best way is method 1 and method 3. The method 2 has many limitations.
On the preview setting page, you can create directory index. This will traverse all the folders to extract the xml layouts. After this, the framework can easily find the layout by name. Otherwise, the framework will load the layout from the preview base url + 'flexname.xml'.
Flexbox Introduction & performance (in Chinese)
Tutorial 1: Create View Controller with xml layout
Tutorial 2: Create Table Cell with xml layout
Tutorial 3: Embed xml layout into traditional view hierarchy
Tutorial 4: Use custom view in xml layout
Tutorial 5: Create reusable view using xml layout file