<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>布局 &#8211; 编程技术记录</title>
	<atom:link href="https://blog.z6z8.cn/category/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/%E5%B8%83%E5%B1%80/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.z6z8.cn</link>
	<description>世界你好!</description>
	<lastBuildDate>Tue, 17 Jan 2023 02:33:33 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>小程序同层渲染&#8211;iOS WKWebView实现</title>
		<link>https://blog.z6z8.cn/2020/01/13/%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%90%8c%e5%b1%82%e6%b8%b2%e6%9f%93-ios-wkwebview%e5%ae%9e%e7%8e%b0/</link>
		
		<dc:creator><![CDATA[holdsky]]></dc:creator>
		<pubDate>Mon, 13 Jan 2020 08:18:33 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[代码片段]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[布局]]></category>
		<guid isPermaLink="false">http://blog.z6z8.cn/?p=769</guid>

					<description><![CDATA[先上代码 RenderWebViewWithNative 我只在模拟器环境中测了。 本文成文使用的环境 Xco [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>先上代码<br />
<a href="/wp-content/uploads/2020/01/RenderWebViewWithNative-1.zip" title="RenderWebViewWithNative">RenderWebViewWithNative</a><br />
我只在模拟器环境中测了。</p>
<p><img decoding="async" src="/wp-content/uploads/2020/01/RenderWebViewWithNative.png" alt="" /></p>
<h1>本文成文使用的环境</h1>
<ul>
<li>Xcode Version 11.3 (11C29)</li>
<li>模拟器版本Version 11.3 (SimulatorApp-912.5 SimulatorKit-570.3 CoreSimulator-681.17)，对应iOS 13.2</li>
</ul>
<h1>同层渲染步骤</h1>
<p>简单说下同层渲染效果，是将Native控件添加到WKWebView的子层级View中，最明显的是z-index 属性可以控制Native控件。详细请阅读https://developers.weixin.qq.com/community/develop/article/doc/000c4e433707c072c1793e56f5c813</p>
<h2>需要前端改造的地方</h2>
<p>为了让WKWebView为Native控件单独生成一个子层级的View，需要改变对应DOM节点的CSS样式,如</p>
<pre><code class="language-html">〈div style="position: fixed; font-size: 50px;overflow: scroll;-webkit-overflow-scrolling: touch" id="zl_native" 〉
            〈zl-native id="zl_native_node"〉world〈zl-native〉
〈/div〉</code></pre>
<p>本文成文环境中测试的结果是:</p>
<ul>
<li>WKWebView只为<code>position: fixed</code>的
<div>标签内容生成单独的子层级视图</li>
<li><code>overflow: scroll;-webkit-overflow-scrolling: touch</code>,在本文成文环境中不起作用；建议读者自行尝试更多的环境，以得到更准确的结论。</li>
</ul>
<h2>需要客户端改造的地方</h2>
<p>首先，当前端加载DOM时，检测到需要Native渲染的节点，需要通过jsbridge通知客户端，把节点的信息告诉客户端。客户端根据节点信息找到对应的子层级view</p>
<pre><code class="language-objc">-(UIView *)find_zl_native_view
{
    UIView *wkcontentview = [self get_wkcontentView];
    NSMutableArray *arr = [wkcontentview.subviews mutableCopy];
    while (arr.count > 0)
    {
        UIView *comp = arr.firstObject;
        [arr removeObjectAtIndex:0];
        if ([@"WKCompositingView" isEqualToString:NSStringFromClass([comp class])])
        {
            if ([comp.layer.name isEqualToString:@" <div> id='zl_native'"]) {
                return comp;
            }
        }

        if (comp.subviews.count > 0)
        {
            [arr addObjectsFromArray:comp.subviews];
        }
    }
    return nil;
}</code></pre>
<p>找到后，在这个子层级view上添加Native控件，渲染对应内容。</p>
<pre><code class="language-objc">-(void)startNativeRender_zl_native_node
{
    UIView *view = [self find_zl_native_view];
    UILabel *lbl = [[UILabel alloc] initWithFrame:view.bounds];
    [view addSubview:lbl];
    lbl.alpha = 0;
    [UIView animateWithDuration:3 animations:^{
        lbl.alpha = 0.6;
        lbl.text = @"world";
        lbl.textColor = [UIColor yellowColor];
        lbl.backgroundColor = [UIColor redColor];
        lbl.font = [UIFont systemFontOfSize:49.5];
    }];
}</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>WKWebView：适配H5页面的显示尺寸</title>
		<link>https://blog.z6z8.cn/2019/11/04/wkwebview%ef%bc%9a%e9%80%82%e9%85%8dh5%e9%a1%b5%e9%9d%a2%e7%9a%84%e6%98%be%e7%a4%ba%e5%b0%ba%e5%af%b8/</link>
					<comments>https://blog.z6z8.cn/2019/11/04/wkwebview%ef%bc%9a%e9%80%82%e9%85%8dh5%e9%a1%b5%e9%9d%a2%e7%9a%84%e6%98%be%e7%a4%ba%e5%b0%ba%e5%af%b8/#respond</comments>
		
		<dc:creator><![CDATA[holdsky]]></dc:creator>
		<pubDate>Mon, 04 Nov 2019 03:29:01 +0000</pubDate>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[布局]]></category>
		<category><![CDATA[WKWebView]]></category>
		<guid isPermaLink="false">http://blog.z6z8.cn/?p=544</guid>

					<description><![CDATA[一般的同样的html代码，在UIWebView和WKWebView中显示效果是不一样的。例如 &#60;!DOC [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>一般的同样的html代码，在UIWebView和WKWebView中显示效果是不一样的。例如</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;span&gt;test_input&lt;/span&gt;
        &lt;input id="test_input" type="text"&gt;
    &lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>显示效果：<img decoding="async" src="/wp-content/uploads/2019/11/wkwebview_uiwebview.png" alt="" /></p>
<p>可以看出两者有明显的区别。<br />
那么如何适配呢？有两个方法（本质上是一个）。<br />
1、如果是H5适配WKWebView的话，需要在H5添加如下代码</p>
<pre><code class="language-html">&lt;meta name="viewport" content="width=device-width"&gt;</code></pre>
<p>完整的html如下</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta name="viewport" content="width=device-width"&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;span&gt;test_input&lt;/span&gt;
        &lt;input id="test_input" type="text"&gt;
    &lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>2、如果是WKWebView适配H5的话，那么就需要替前端添加相同的H5代码，实现如下</p>
<pre><code class="language-swift"> //js代码，在文档加载完毕后，添加head的子节点
 //节点内容为&lt;meta name="viewport" content="width=device-width"&gt;
        let jScript = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
        let wkUScript = WKUserScript.init(source: jScript, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: true);
        let wkUController = WKUserContentController.init();
        wkUController.addUserScript(wkUScript);

        let wkconfig = WKWebViewConfiguration.init();
        wkconfig.userContentController = wkUController;

        _webView = WKWebView.init(frame: CGRect.init(x: 0, y: 0, width: self.view.bounds.size.width, height: self.view.bounds.size.height), configuration: wkconfig);
        self.view.addSubview(_webView);

        let htmlfile = Bundle.main.path(forResource: "test", ofType: ".html");
        let url = URL.init(fileURLWithPath: htmlfile!);
        let request = URLRequest.init(url: url);
        _webView.load(request);</code></pre>
<p>参考 <a href="https://blog.csdn.net/GYMotgm/article/details/77944163">https://blog.csdn.net/GYMotgm/article/details/77944163</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.z6z8.cn/2019/11/04/wkwebview%ef%bc%9a%e9%80%82%e9%85%8dh5%e9%a1%b5%e9%9d%a2%e7%9a%84%e6%98%be%e7%a4%ba%e5%b0%ba%e5%af%b8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>CSS 头脚+中间两列布局</title>
		<link>https://blog.z6z8.cn/2019/10/10/css-%e5%a4%b4%e8%84%9a%e4%b8%ad%e9%97%b4%e4%b8%a4%e5%88%97%e5%b8%83%e5%b1%80/</link>
		
		<dc:creator><![CDATA[holdsky]]></dc:creator>
		<pubDate>Thu, 10 Oct 2019 11:46:44 +0000</pubDate>
				<category><![CDATA[代码片段]]></category>
		<category><![CDATA[布局]]></category>
		<category><![CDATA[CSS]]></category>
		<guid isPermaLink="false">http://blog.z6z8.cn/?p=478</guid>

					<description><![CDATA[效果图 &#60;html&#62; &#60;head&#62; &#60;style type="text/css" [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>效果图<br />
<img decoding="async" src="/wp-content/uploads/2019/10/css%E5%A4%B4%E8%84%9A%E4%B8%AD%E9%97%B4%E4%B8%A4%E5%88%97.png" alt="" /></p>
<pre><code class="language-html">&lt;html&gt;
  &lt;head&gt;
      &lt;style type="text/css"&gt;
      /* 整体Body */
            .flex-body {
            width: 100%;
            height: 100%;
            margin: 0px;
            }

            /* 头 高70px*/
            .flex-header {
            background-color: aqua;
            height: 70px;
            width: 100%;
            }
            /* 中间左侧，绝对定位，宽度50%，高度由top和bottom决定，
            top和bottom分别是 flex-header ，flex-footer的高度*/
            .flex-left-main {
            position: absolute;
            background-color: red;
            width: 50%;
            top: 70px;
            bottom: 60px;
            }
            /* 中间左侧，绝对定位，宽度50%，高度由top和bottom决定，
            margin-left: 50%
            top和bottom分别是 flex-header ，flex-footer的高度*/
            .flex-right-main {
            position: absolute;
            background-color: blue;
            width: 50%;
            top: 70px;
            bottom: 60px;
            margin-left: 50%;
            }
            /* 脚 高60px */
            .flex-footer {
            position: absolute;
            bottom: 0px;
            width:100%;
            height: 60px;
            background-color: bisque;
            }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body class="flex-body"&gt;
    &lt;div id="flex-header" class="flex-header"&gt;&lt;/div&gt;
    &lt;div id="flex-left-main" class="flex-left-main"&gt;&lt;/div&gt;
    &lt;div id="flex-right-main" class="flex-right-main"&gt;&lt;/div&gt;
    &lt;div id="flex-footer" class="flex-footer"&gt;&lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>学习笔记：iOS 使用Yoga布局&#8212;-一种FlexBox布局实现</title>
		<link>https://blog.z6z8.cn/2019/09/26/%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%ef%bc%9aios-%e4%bd%bf%e7%94%a8yoga%e5%b8%83%e5%b1%80-%e4%b8%80%e7%a7%8dflexbox%e5%b8%83%e5%b1%80%e5%ae%9e%e7%8e%b0/</link>
		
		<dc:creator><![CDATA[holdsky]]></dc:creator>
		<pubDate>Thu, 26 Sep 2019 11:19:37 +0000</pubDate>
				<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[布局]]></category>
		<guid isPermaLink="false">http://blog.z6z8.cn/?p=417</guid>

					<description><![CDATA[集成 Yoga是Facebook开源的基于CSS FlexBox布局框架，核心使用C++实现的，在iOS上并不 [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>集成</h1>
<p>Yoga是Facebook开源的基于CSS FlexBox布局框架，核心使用C++实现的，在iOS上并不需要直接集成C++代码，只需通过CocoaPod引入<code>YogaKit</code>（间接集成C++代码）</p>
<pre><code># Podfile

platform :ios, '8.0'
use_frameworks!

target "TestProject" do
    pod 'YogaKit'
end</code></pre>
<p><img decoding="async" src="http://139.155.43.7/wp-content/uploads/2019/09/屏幕快照-2019-09-27-上午11.59.57.png" alt="" /></p>
<h1>使用</h1>
<p>集成后，YogaKit提供了UIView的方法扩展</p>
<pre><code>// UIView+Yoga.h
@property (nonatomic, readonly, strong) YGLayout *yoga;</code></pre>
<p><code>yoga</code>类型为<code>YGLayout</code>，描述了UIView如何布局。</p>
<p>简单示例</p>
<pre><code class="language-obj-c">
//代码源自 https://www.jianshu.com/p/95bf92143141
-(void)test
{

    [self.view configureLayoutWithBlock:^(YGLayout * layout) {
        layout.isEnabled = YES;
        layout.width = YGPointValue(self.view.bounds.size.width);
        layout.height = YGPointValue(self.view.bounds.size.height);
        layout.alignItems = YGAlignCenter;
    }];

    UIView *contentView = [[UIView alloc]init];
    contentView.backgroundColor = [UIColor lightGrayColor];
    [contentView configureLayoutWithBlock:^(YGLayout * layout) {
        layout.isEnabled = true;
        // 4
        layout.flexDirection =  YGFlexDirectionRow;
        layout.width = YGPointValue(320);
        layout.height = YGPointValue(80);
        layout.marginTop = YGPointValue(100);

        layout.padding =  YGPointValue(10);//设置了全部子项目的填充值
    }];

    UIView *child1 = [[UIView alloc]init];
    child1.backgroundColor = [UIColor redColor];
    [child1 configureLayoutWithBlock:^(YGLayout * layout) {
        layout.isEnabled = YES;
        layout.width = YGPointValue(80);
        layout.marginRight = YGPointValue(10);
    }];

    UIView *child2 = [[UIView alloc]init];
    child2.backgroundColor = [UIColor blueColor];
    [child2 configureLayoutWithBlock:^(YGLayout * layout) {
        layout.isEnabled = YES;
        layout.width = YGPointValue(80);
        layout.flexGrow = 1;
        layout.height = YGPointValue(20);
        layout.alignSelf = YGAlignCenter;

    }];

    [contentView addSubview:child1];
    [contentView addSubview:child2];
    [self.view addSubview:contentView];
    [self.view.yoga applyLayoutPreservingOrigin:YES];
}</code></pre>
<p>注意:</p>
<p>无特殊情况，方法<code>applyLayoutPreservingOrigin</code>最好由根节点执行</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>学习笔记：Yoga 布局属性</title>
		<link>https://blog.z6z8.cn/2019/09/23/%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%ef%bc%9ayoga-%e5%b8%83%e5%b1%80%e5%b1%9e%e6%80%a7/</link>
		
		<dc:creator><![CDATA[holdsky]]></dc:creator>
		<pubDate>Mon, 23 Sep 2019 11:12:45 +0000</pubDate>
				<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[布局]]></category>
		<category><![CDATA[yoga]]></category>
		<guid isPermaLink="false">http://blog.z6z8.cn/?p=382</guid>

					<description><![CDATA[本文为Google翻译+人工修正文章 参考 https://yogalayout.com/docs [TOC] [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>本文为Google翻译+人工修正文章 参考 <a href="https://yogalayout.com/docs">https://yogalayout.com/docs</a></p>
<p>[TOC]</p>
<h1>主轴和交叉轴 (main axis/cross axis)</h1>
<p><img decoding="async" src="/wp-content/uploads/2019/09/屏幕快照-2019-09-23-下午5.17.36-1.png" width = "400" height = "200" alt="图片名称" align=center /></p>
<h1>绝对布局和相对布局 (Absolute/Relative Layout)</h1>
<p>元素布局分为两种，一种是绝对布局，一种是相对布局。</p>
<ul>
<li>相对布局 (默认)</li>
</ul>
<p>默认情况下，元素的位置相对。 这意味着元素将根据布局的正常流程进行定位，然后根据上，右，下和左的值相对于该位置偏移。 偏移量不会影响任何同级元素或父元素的位置。</p>
<ul>
<li>绝对布局</li>
</ul>
<p>绝对位置绝对放置时，元素不会参与正常的布局流程。 相反，它的布局与兄弟姐妹无关。 根据上，右，下和左的值确定位置。</p>
<p><code>译者注：注意取值顺序，上（top），右（right），下（bottom），左（left）</code></p>
<p>位置值上（top），右（right），下（bottom），左（left）的行为取决于元素的位置类型(相对布局或绝对布局)。 对于相对布局元素，它们沿指定方向偏移元素的位置。 对于绝对布局元素，这些属性指定了元素的相对于父元素的同一边的偏移量（<code>译者注，这句有点绕，其实就是同边对同边，例如子元素的上（top）是从父元素的上（top）开始算起</code>）。</p>
<p>演示效果参见 <a href="https://yogalayout.com/docs/absolute-relative-layout">https://yogalayout.com/docs/absolute-relative-layout</a></p>
<h1>布局方向（Layout direction）</h1>
<p>指在层次结构中，子项和文本的布局方向。 布局方向也会影响边的起点和终点。</p>
<p>默认情况下，Yoga沿LTR布局方向进行布局。在此模式下，“start”是指左侧，“end”是指右侧。</p>
<p><code>使用RTL方向时，应通过将方向传递给CalculateLayout调用或在根节点上设置方向来自定义此功能</code>。</p>
<ul>
<li>LTR（默认）从左到右排列。 应用于元素边距和填充的开始在左侧。</li>
<li>RTL 从右到左排列。 应用于元素边距和填充的开始在右侧。</li>
</ul>
<h1>宽度和高度（ Width and Height）</h1>
<p>Yoga中的width属性指定元素内容区域的宽度。 同样，height属性指定元素内容区域的高度。</p>
<p>宽度和高度都可以采用以下值：</p>
<ul>
<li>AUTO是默认值，Yoga根据元素的内容（无论是其他子元素，文本还是图像）计算元素的宽度/高度。</li>
<li>PIXELS 定义绝对像素的宽度/高度。 取决于Yoga节点上设置的其他属性(<code>译者注:如flex grow ，padding</code>)，这可能是节点的最终尺寸，也可能不是。</li>
<li>PERCENTAGE 分别以其父对象的宽度或高度的百分比定义宽度或高度。</li>
</ul>
<p>演示效果参见 <a href="https://yogalayout.com/docs/width-height">https://yogalayout.com/docs/width-height</a></p>
<h2>宽高的最值(Max / Min Width and Height)</h2>
<p>以下所有属性均设置元素的最大和最小尺寸限制。<code> 这些属性的优先级高于所有其他属性，并且将始终受到(布局动作)的考虑</code>。 约束可以指定为绝对像素值，也可以指定为其父级大小的百分比。 默认情况下，所有这些约束都是<code>undefined</code>。</p>
<ul>
<li>MAX WIDTH</li>
<li>MIN WIDTH</li>
<li>MAX HEIGHT</li>
<li>MIN HEIGHT</li>
</ul>
<p>演示效果参见 <a href="https://yogalayout.com/docs/min-max">https://yogalayout.com/docs/min-max</a></p>
<h2>宽高比(Aspect ratio)</h2>
<p>AspectRatio是Yoga引入的属性，在CSS Flexbox规范中未作为可设置的属性显示。Flexbox确实具有宽高比的概念，尽管对于具有固有高宽比的事物（例如图像）。</p>
<p>Yoga中的宽高比属性具有以下属性：</p>
<ul>
<li>接受任何大于0的浮点值，默认值为undefined。</li>
<li>定义为节点的宽度与高度之比，例如 如果节点的宽高比为2，则其宽度是其高度的两倍。</li>
<li>遵守项目(item，这里只布局元素)的最小和最大尺寸。</li>
<li>具有比<code>flex grow（弹性增长）</code>更高的优先级</li>
<li>如果设置了宽高比，宽度和高度，则将覆盖交叉轴尺寸。</li>
</ul>
<p>演示效果参见 <a href="https://yogalayout.com/docs/aspect-ratio/">https://yogalayout.com/docs/aspect-ratio/</a></p>
<h1>对齐(Align)</h1>
<h2>沿交叉轴对齐内容 （Align Content）</h2>
<p>定义沿交叉轴（cross-axis，也主轴垂直的轴）的线分布。 仅当使用flex wrap将项目包装到多行时，此功能才有效。</p>
<p>可用值有：</p>
<ul>
<li>FLEX START（DEFAULT）将环绕线（wraped line）对齐到容器交叉轴的起点。</li>
<li>FLEX END 将环绕线（wraped line）对齐到容器交叉轴的末端。</li>
<li>STRETCH 拉伸环绕线（wraped line）以匹配容器交叉轴的高度。</li>
<li>CENTER 将环绕线（wraped line）对齐到容器交叉轴的中心。</li>
<li>SPACE BETWEEN 顶交叉轴的两端对齐。</li>
<li>SPACE AROUND 沿交叉轴均匀分布，和SPACE BETWEEN 有些像，但不相同，可参考演示效果。</li>
</ul>
<p>演示效果参见 <a href="https://yogalayout.com/docs/align-content">https://yogalayout.com/docs/align-content</a></p>
<h2>沿主轴对齐内容(Justify Content)</h2>
<p>描述了如何沿主轴对齐子项。</p>
<ul>
<li>FLEX START（DEFAULT）将容器的子项与容器主轴的起点对齐。</li>
<li>FLEX END 将容器的子项与容器主轴的末端对齐。</li>
<li>CENTER 将容器的子项与容器主轴的中心对齐。</li>
<li>SPACE BETWEEN 子项在容器的主轴上顶两端分布。</li>
<li>SPACE AROUND 和SPACE BETWEEN 有些像，但不顶两端。</li>
<li>SPACE EVENLY，子项沿主轴均匀分布。间距以及和容器开始边缘的间距、结束边缘的间距相同。</li>
</ul>
<p>演示效果参见 <a href="https://yogalayout.com/docs/justify-content">https://yogalayout.com/docs/justify-content</a></p>
<h2>对齐项（Align Item）</h2>
<p>描述子项如何围绕交叉轴对齐。 对齐项与<code>(内容对齐)justify-content</code>非常相似，但是对齐项不是应用于主轴，而是应用于交叉轴。</p>
<ul>
<li>STRETCH （默认）拉伸子项以使其与容器交叉轴的高度匹配。</li>
<li>FLEX START 将子项与容器交叉轴的开始端对齐。</li>
<li>FLEX END 将子项与容器交叉轴的结束端对齐。</li>
<li>CENTER 将容器的子代与容器的交叉轴中心对齐。</li>
<li>BASELINE 使子项沿着共同的基线对齐。可以将单个孩子设置为其父母的参考基准。</li>
</ul>
<p>演示效果参见 <a href="https://yogalayout.com/docs/align-items">https://yogalayout.com/docs/align-items</a></p>
<h3>自我对齐(Align Self)</h3>
<p>自我对齐具有与对齐项（Align Items）相同的选项和效果，但是可以对单个子项应用此属性以更改其在其父级中的对齐方式，而不是影响容器中的子项目。 自我对齐(Align self)会覆盖父项通过(Align items)项目设置的任何选项。</p>
<p><code>译者注，Align Item影响子项，而Align Self只针对自己，会覆盖通过Align Item赋予的值</code></p>
<p>演示效果参见 <a href="https://yogalayout.com/docs/align-items">https://yogalayout.com/docs/align-items</a></p>
<h1>伸缩(Flex)</h1>
<h2>伸缩方向（Flex Direction）</h2>
<p>伸缩方向控制子项的伸缩方向。伸缩方向是相对于于主轴和交叉轴来说的。</p>
<ul>
<li>ROW （默认）（主轴方向）从左到右对齐子项。 如果启用了环绕(wrap)，则下一行将从容器左侧第一项下方开始。</li>
<li>COLUMN （交叉轴方向） 从上至下对齐子项。 如果启用了环绕(wrap)，则下一行将从容器顶部的左第一项开始。</li>
<li>ROW REVERSE （主轴方向）从右向左对齐子项。 如果启用了环绕(wrap)，则下一行将从容器右侧的第一项开始。</li>
<li>COLUMN REVERSE （交叉轴方向）从下到上对齐子项。 如果启用了环绕(wrap)，则下一行将从容器底部的第一行开始。</li>
</ul>
<p>演示效果参见 <a href="https://yogalayout.com/docs/flex-direction">https://yogalayout.com/docs/flex-direction</a></p>
<h2>环绕换行(Flex Wrap)</h2>
<p>默认情况下，可伸缩子项被强制排布为一行。</p>
<ul>
<li>flex wrap 属性是在容器上设置的，并控制当子项沿主轴布局溢出容器大小时发生的情况。 如果允许环绕，则根据需要将项目沿主轴布成多行。</li>
<li>wrap reverse 换行的行为相同，但顺序相反。</li>
</ul>
<p>换行时，可以使用<code>对齐内容 (align content )</code>指定行在容器中的放置方式。</p>
<p>演示效果参见 <a href="https://yogalayout.com/docs/flex-wrap">https://yogalayout.com/docs/flex-wrap</a></p>
<h2>伸缩(Flex)--基础(Basis),增长(Grow)和缩小(Shrink)</h2>
<ul>
<li>FLEX GROW 描述了容器空间应如何<code>沿主轴</code>分配给子项。 放置其子项后，容器将根据其子项指定的flex grow值分配所有剩余空间。 Flex grow接受大于等于0的任何浮点值，默认值为0。 容器将在孩子之间分配剩余的空间，该剩余空间将根据孩子的弹性增长值来加权。</li>
</ul>
<pre><code>译者注：
1、假设主轴为宽度方向
2、那么再假设容器宽度为10
3、假设有3个宽度为2的子项a,b,c
4、再假设a的flex grow为3，b的flex grow为1，c的flex grow为0

先沿着主轴布局a,b,c，三个子项占据宽度3x2=6
还剩下宽度4,根据各自的flex grow,计算加权比重得出
a占据剩余宽度的3/(3+1+0)=75%，也就是3
b占据剩余宽度的1/(3+1+0)=25%，也就是1
c占据剩余宽度的0/(3+1+0)=0%，也就是0

最后
a的宽度为 2+3 = 5
b的宽度为 2+1 = 3
c的宽度为 2+0 = 2
</code></pre>
<ul>
<li>FLEX SHRINK 描述了在子项<code>主轴上</code>的总大小溢出容器大小的情况下如何沿主轴收缩子项。 flex shrink 与flex grow非常相似，也计算加权比重和负空间（溢出大小）相乘，得出需要缩小的尺寸。 Flex Shink接受任何大于等于0的浮点值，默认值为1。 容器将根据其子项的flex shink值对子项进行收缩。 （如何收缩可以参考上面flex grow的示例）</li>
<li>FLEX BASIS 是一种与轴无关的方式，用于沿主轴提供子项的默认大小。 如果子项的父级是具有flex row方向的容器，则设置子项的flex basis似于设置子项的宽度； 如果子项的父级是具有flex column方向的容器，则设置子项的flex basis似于设置子项的高度。 flex basis的默认大小在执行flex grow动作和flex shrink动作之前计算。</li>
</ul>
<p>演示效果参见 <a href="https://yogalayout.com/docs/flex/">https://yogalayout.com/docs/flex/</a></p>
<h1>边距（Margins）,填充( Paddings), 边框( Borders)</h1>
<ul>
<li>MARGIN 影响节点外部周围的间距。 具有边距的节点将使其自身偏离其父级的边界，但也会偏移所有同级的位置。 如果父节点是自动调整大小的，则节点的边距将对其父节点的总大小有所贡献。</li>
<li>PADDING 会影响它所应用的节点的大小。在 Yoga中，填充就像<code>box-sizing:border-box;</code>一样。 也就是说，如果元素具有显式大小，则填充不会增加元素的总大小。 对于自动调整大小的节点，填充将增加节点的大小以及偏移任何子节点的位置。</li>
<li>BORDER 在Yoga中的行为与填充(PADDING)完全一样，因为作为单独的属性存在，优先级高于框架的暗示（注，类似于框架的全局设定）。 然而，Yoga并没有做任何绘图，因此仅在布局过程中使用此信息，边框的行为完全类似于填充。</li>
</ul>
<p>演示效果参见 <a href="https://yogalayout.com/docs/margins-paddings-borders/">https://yogalayout.com/docs/margins-paddings-borders/</a></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
