<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>菩提树下有只蝉</title>
    <description>Sefer的个人博客，内容主要是IT技术，传统文化，个人日记。
</description>
    <link>http://shaofe.ng/</link>
    <atom:link href="http://shaofe.ng/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Sun, 09 Dec 2018 18:02:55 +0800</pubDate>
    <lastBuildDate>Sun, 09 Dec 2018 18:02:55 +0800</lastBuildDate>
    <generator>Jekyll v3.8.5</generator>
    
      <item>
        <title>N*M点阵中正方形的个数</title>
        <description>&lt;h3 id=&quot;简单问题&quot;&gt;简单问题&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/assets/square/square_img1.png&quot; alt=&quot;Image1&quot; width=&quot;150px&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;首先看一个简单的问题。如图所示，这是一个大小为 &lt;script type=&quot;math/tex&quot;&gt;4*4&lt;/script&gt; 的&lt;strong&gt;点阵&lt;/strong&gt;，问该点阵中共有多少个正方形？&lt;/p&gt;

&lt;p&gt;很容易可以发现，只需统计边长为1的正方形个数 &lt;script type=&quot;math/tex&quot;&gt;(4-1)^2&lt;/script&gt;，边长为2的正方形个数 &lt;script type=&quot;math/tex&quot;&gt;(4-2)^2&lt;/script&gt;，和边长为3的正方形个数 &lt;script type=&quot;math/tex&quot;&gt;(4-3)^2&lt;/script&gt;，共计14个正方形。（注意，&lt;script type=&quot;math/tex&quot;&gt;4*4&lt;/script&gt; 的点阵边长为3）。 &lt;script type=&quot;math/tex&quot;&gt;N*N&lt;/script&gt; 点阵的正方形总数即&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align}
\sum_{s=1}^{N-1} s^2 &amp;= \dfrac{N(N-1)(2N-1)}{6}
\end{align} %]]&gt;&lt;/script&gt;

&lt;hr /&gt;
&lt;p&gt;&lt;br /&gt;
&lt;img src=&quot;/assets/square/square_img2.png&quot; alt=&quot;Image2&quot; height=&quot;150px&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;扩展到 &lt;script type=&quot;math/tex&quot;&gt;N*M&lt;/script&gt; 的点阵，如上图 &lt;script type=&quot;math/tex&quot;&gt;4*6&lt;/script&gt; 的点阵，正方形边长只需统计到N和M中较小的那一边的边长即可。对于每个边长s，正方形个数为 &lt;script type=&quot;math/tex&quot;&gt;(N-s)*(M-s)&lt;/script&gt; 。 &lt;script type=&quot;math/tex&quot;&gt;N*M&lt;/script&gt; 点阵的正方形总数即（假设 &lt;script type=&quot;math/tex&quot;&gt;% &lt;![CDATA[
N&lt;M %]]&gt;&lt;/script&gt; ）&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align}
\sum_{s=1}^{N-1} (M-s)*(N-s) &amp;= \sum_{s=1}^{N-1} MN-(M+N)s+s^2 \\
                             &amp;= MN(N-1) - (M+N)\dfrac{(N-1)N}{2} + \dfrac{N(N-1)(2N-1)}{6} \\
                             &amp;= \dfrac{N(N-1)(3M-N-1)}{6}

\end{align} %]]&gt;&lt;/script&gt;

&lt;h3 id=&quot;扩展问题&quot;&gt;扩展问题&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/assets/square/square_img3.png&quot; alt=&quot;Image3&quot; width=&quot;150px&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;我们扩展一下正方形的定义。如图所示，这是一个大小为 &lt;script type=&quot;math/tex&quot;&gt;4*4&lt;/script&gt; 的点阵，绿色和红色正方形都算作合法的正方形，问该点阵中共有多少个正方形？&lt;/p&gt;

&lt;p&gt;首先我们定义上图中绿色边的正方形为&lt;strong&gt;基准&lt;/strong&gt;正方形。根据观察可以发现，一个边长为s的基准正方形点阵中共包含s个合法的正方形。因此对于每个边长s，&lt;strong&gt;基准正方形&lt;/strong&gt;个数为 &lt;script type=&quot;math/tex&quot;&gt;(N-s)^2&lt;/script&gt;（由简单问题得知），再乘以s，即为该边长s的所有正方形个数。 &lt;script type=&quot;math/tex&quot;&gt;N*N&lt;/script&gt; 点阵的正方形总数即&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align}
\sum_{s=1}^{N-1} s*(N-s)^2 &amp;= \sum_{s=1}^{N-1} N^2s-2Ns^2+s^3 \\
                           &amp;= N^2\dfrac{N(N-1)}{2}-2N\dfrac{N(N-1)(2N-1)}{6}+\dfrac{(N-1)^2N^2}{4} \\
                           &amp;= \dfrac{N^4-N^2}{12}

\end{align} %]]&gt;&lt;/script&gt;

&lt;hr /&gt;
&lt;p&gt;&lt;br /&gt;
&lt;img src=&quot;/assets/square/square_img4.png&quot; alt=&quot;Image4&quot; height=&quot;150px&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;同样，扩展到 &lt;script type=&quot;math/tex&quot;&gt;N*M&lt;/script&gt; 的点阵，对于每个边长s，正方形个数为 &lt;script type=&quot;math/tex&quot;&gt;(N-s)*(M-s)*s&lt;/script&gt; 。 &lt;script type=&quot;math/tex&quot;&gt;N*M&lt;/script&gt; 点阵的正方形总数即（假设 &lt;script type=&quot;math/tex&quot;&gt;% &lt;![CDATA[
N&lt;M %]]&gt;&lt;/script&gt; ）&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align}
\sum_{s=1}^{N-1} s*(M-s)*(N-s) &amp;= \sum_{s=1}^{N-1} MNs-(M+N)s^2+s^3 \\
                               &amp;= MN\dfrac{N(N-1)}{2} - (M+N)\dfrac{N(N-1)(2N-1)}{6} + \dfrac{(N-1)^2N^2}{4} \\
                               &amp;= \dfrac{(2M-N)(N-1)N(N+1)}{12}

\end{align} %]]&gt;&lt;/script&gt;

&lt;h3 id=&quot;参考资料&quot;&gt;参考资料&lt;/h3&gt;

&lt;p&gt;[1] &lt;a href=&quot;https://code.google.com/codejam/contest/8284486/dashboard&quot;&gt;Google Kickstart Round A 2017 Problem A.Square Counting&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[2] &lt;a href=&quot;https://www.quora.com/How-many-squares-have-all-four-vertices-in-an-n-times-n-grid-of-dots&quot;&gt;Quora&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Tue, 07 Mar 2017 18:10:20 +0800</pubDate>
        <link>http://shaofe.ng/%E6%95%B0%E5%AD%A6/N-M%E7%9A%84%E7%82%B9%E9%98%B5%E4%B8%AD%E6%AD%A3%E6%96%B9%E5%BD%A2%E7%9A%84%E4%B8%AA%E6%95%B0/</link>
        <guid isPermaLink="true">http://shaofe.ng/%E6%95%B0%E5%AD%A6/N-M%E7%9A%84%E7%82%B9%E9%98%B5%E4%B8%AD%E6%AD%A3%E6%96%B9%E5%BD%A2%E7%9A%84%E4%B8%AA%E6%95%B0/</guid>
        
        <category>algebraic</category>
        
        <category>geometry</category>
        
        
        <category>数学</category>
        
      </item>
    
      <item>
        <title>自定义cocos2d-x引擎中的模态框类和消息通知类</title>
        <description>&lt;h3 id=&quot;模态框类modal&quot;&gt;模态框类（Modal）&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;模态框&lt;/code&gt;就是一个包含内容和按钮的对话框，用户必须先响应对话框才能继续操作应用程序。&lt;/p&gt;

&lt;p&gt;本项目中的模态框需求是可以自定义标题、内容，可选关闭按钮以及设置功能按钮组。我们将这个模态框类写成一个Layer，便于项目全局使用，Layer是cocos2d-x中的概念，可以参考&lt;a href=&quot;http://www.cocos2d-x.org/wiki/Layer&quot;&gt;这里&lt;/a&gt;。&lt;/p&gt;

&lt;p&gt;模态框类的参考代码如下：&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;PopLayer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Layer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//设置成员变量&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;layerBg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;titleLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;listener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;menu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cancelMenu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;

  &lt;span class=&quot;na&quot;&gt;ctor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_super&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;winSize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;layerBg&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Sprite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;modal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;layerBg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setPosition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;layerBg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setLocalZOrder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;layerBg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;titleLabel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;LabelTTF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Arial&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;titleLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setFontFillColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;BLACK&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;titleLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setAnchorPoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;titleLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setPosition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;230&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;titleLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;395&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;titleLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;LabelTTF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Arial&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setFontFillColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;BLACK&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setAnchorPoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setPosition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;230&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;340&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setDimensions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;460&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;140&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textAlign&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;TEXT_ALIGNMENT_CENTER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;MenuItemFont&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setFontName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Arial&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;MenuItemFont&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setFontSize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cancelBtn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;MenuItemFont&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Close&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;sender&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hide&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cancelBtn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;RED&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cancelBtn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setAnchorPoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cancelBtn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setPosition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cancelMenu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Menu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cancelBtn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cancelMenu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setAnchorPoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cancelMenu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setPosition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;730&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cancelBtn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;width&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;395&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cancelMenu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listener&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;EventListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;EventListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;TOUCH_ONE_BY_ONE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;swallowTouches&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;onTouchBegan&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;touch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//设置按钮组&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;addMenu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;menu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;menu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;menu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;menu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//设置标题&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;setTitle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;titleLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;titleLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setPosition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;230&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;titleLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;395&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//设置显示内容&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;setContent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setPosition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;230&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;340&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//设置关闭按钮&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;setCloseBtn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;flag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cancelMenu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setVisible&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;flag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//显示模态框&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;eventManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setVisible&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//隐藏模态框（一般写在回调里）&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;hide&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;removeChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;menu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;menu&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setVisible&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;eventManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;removeListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;listener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;调用代码如下：&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;c1&quot;&gt;//新建Layer，添加到场景（Scene）中&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;modalLayer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;PopLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;this is title&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;this is content&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;modalLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setVisible&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;//一开始不想让这个层显示&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;modalLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//调用Modal类&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//添加自定义的菜单menu&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;modalLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addMenu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;menu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//设置标题&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;modalLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setTitle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Title Example&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//设置内容&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;modalLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setContent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Content Example&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//不显示关闭按钮&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;modalLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setCloseBtn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//显示模态框&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;modalLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//关闭模态框&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;modalLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;hide&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;//注意：一般关闭模态框层的代码写在按钮的回调中&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;消息通知类toast&quot;&gt;消息通知类（Toast）&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Toast&lt;/code&gt;是一个简易的消息提示框。当显示Toast时，它永远不会获得焦点，无法被点击。用户可以对应用程序的其他部分进行操作。Toast类的思想就是尽可能不引人注意，同时还向用户显示信息，希望他们看到。而且Toast显示的时间有限，Toast会根据用户设置的显示时间后自动消失。&lt;/p&gt;

&lt;p&gt;Toast类的参考代码如下：&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ToastLayer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Layer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;ctor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_super&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;winSize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;bg&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Sprite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;bg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setPosition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;LabelTTF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Arial&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setFontFillColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;BLACK&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setAnchorPoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setPosition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;560&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setDimensions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;860&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;70&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textAlign&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;TEXT_ALIGNMENT_CENTER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;verticalAlign&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;VERTICAL_TEXT_ALIGNMENT_CENTER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setCascadeOpacityEnabled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//设置Toast显示内容&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;setContent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//设置Toast显示时间，包括显示持续时间和淡出持续时间&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;delay&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;delayOut&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;delay&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;timeOut&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sec&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setOpacity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;runAction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;sequence&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;delayTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;delayOut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;fadeOut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;timeOut&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)));&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;调用代码如下：&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;c1&quot;&gt;//新建Layer，添加到场景（Scene）中&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;toastLayer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;ToastLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Welcome to Toast&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;toastLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setOpacity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//初始设置Toast层不显示&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;toastLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//调用Toast类&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//设置Toast显示内容&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;toastLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setContent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//显示Toast&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;toastLayer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;总结&quot;&gt;总结&lt;/h3&gt;

&lt;p&gt;我的代码还有很多瑕疵，有些地方处理得不严谨，仅供大家作个参考，希望懂cocos2dx的大神能够提出一些批评。欢迎大家在评论里交流学习。&lt;/p&gt;
</description>
        <pubDate>Fri, 01 Apr 2016 09:45:22 +0800</pubDate>
        <link>http://shaofe.ng/%E6%8A%80%E6%9C%AF%E6%9D%82%E8%B0%88/%E8%87%AA%E5%AE%9A%E4%B9%89cocos2d-x-javascript%E4%B8%AD%E7%9A%84%E6%A8%A1%E6%80%81%E6%A1%86%E7%B1%BB%E5%92%8CToast%E7%B1%BB/</link>
        <guid isPermaLink="true">http://shaofe.ng/%E6%8A%80%E6%9C%AF%E6%9D%82%E8%B0%88/%E8%87%AA%E5%AE%9A%E4%B9%89cocos2d-x-javascript%E4%B8%AD%E7%9A%84%E6%A8%A1%E6%80%81%E6%A1%86%E7%B1%BB%E5%92%8CToast%E7%B1%BB/</guid>
        
        <category>cocos2d-x</category>
        
        <category>javascript</category>
        
        
        <category>技术杂谈</category>
        
      </item>
    
      <item>
        <title>一元线性回归模型的参数估计</title>
        <description>&lt;p&gt;PRF(Population Regression Function): 总体回归函数&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;Y_i = \beta_1 + \beta_2X_i + u_i&lt;/script&gt;

&lt;p&gt;SRF(Sample Regression Function): 样本回归函数&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align}
Y_i &amp;= \hat{\beta_1} + \hat{\beta_2}X_i + \hat{u_i} \\
	&amp;= \hat{Y_i} + \hat{u_i}
\end{align} %]]&gt;&lt;/script&gt;

&lt;p&gt;PRF无法直接观测得到，因此我们需要通过SRF来估计PRF，即 &lt;script type=&quot;math/tex&quot;&gt;\hat{Y_i}&lt;/script&gt; 是 &lt;script type=&quot;math/tex&quot;&gt;Y_i&lt;/script&gt; 的估计值。&lt;/p&gt;

&lt;p&gt;将SRF作如下变换：&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align}
\hat{u_i} &amp;= Y_i - \hat{Y_i} \\
		  &amp;= Y_i - \hat{\beta_1} - \hat{\beta_2}X_i
\end{align} %]]&gt;&lt;/script&gt;

&lt;p&gt;&lt;script type=&quot;math/tex&quot;&gt;\hat{u_i}&lt;/script&gt; 即样本中，实际 &lt;script type=&quot;math/tex&quot;&gt;X_i&lt;/script&gt; 对应的 &lt;script type=&quot;math/tex&quot;&gt;Y_i&lt;/script&gt; 值与SRF估计出来的 &lt;script type=&quot;math/tex&quot;&gt;\hat{Y_i}&lt;/script&gt; 值之差。&lt;/p&gt;

&lt;p&gt;要想 &lt;script type=&quot;math/tex&quot;&gt;\hat{Y_i}&lt;/script&gt; 与  &lt;script type=&quot;math/tex&quot;&gt;Y_i&lt;/script&gt; 与 尽量接近，即，求参数 &lt;script type=&quot;math/tex&quot;&gt;\hat{\beta_1},\hat{\beta_2}&lt;/script&gt; 的估计值，使得 &lt;script type=&quot;math/tex&quot;&gt;\sum \hat{u_i^2}&lt;/script&gt; 最小。&lt;/p&gt;

&lt;p&gt;根据&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align}
\sum \hat{u_i^2} &amp;= \sum (Y_i - \hat{Y_i})^2 \\
                 &amp;= \sum (Y_i - \hat{\beta_1} - \hat{\beta_2}X_i)^2
\end{align} %]]&gt;&lt;/script&gt;

&lt;p&gt;若要 &lt;script type=&quot;math/tex&quot;&gt;\sum \hat{u_i^2}&lt;/script&gt; 最小，即求 &lt;script type=&quot;math/tex&quot;&gt;\sum (Y_i - \hat{\beta_1} - \hat{\beta_2}X_i)^2&lt;/script&gt; 关于 &lt;script type=&quot;math/tex&quot;&gt;(\hat{\beta_1},\hat{\beta_2})&lt;/script&gt; 的二元函数的最小值。分别对 &lt;script type=&quot;math/tex&quot;&gt;(\hat{\beta_1},\hat{\beta_2})&lt;/script&gt; 求偏微分，并令其等于0，可得（推导过程省略）&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align}
\sum Y_i &amp;= n\hat{\beta_1} + \hat{\beta_2}\sum X_i \\
\sum Y_iX_i &amp;= \hat{\beta_1}\sum X_i + \hat{\beta_2}\sum X_i^2
\end{align} %]]&gt;&lt;/script&gt;

&lt;p&gt;联立上述两个等式，可得&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align}
\hat{\beta_2} &amp;= \dfrac{n\sum X_iY_i - \sum X_i \sum Y_i}{n\sum X_i^2 - (\sum X_i)^2} \\ \\
              &amp;= \dfrac{\sum X_iY_i - n\bar{X}\bar{Y}}{\sum X_i^2 - n\bar{X}\bar{X}} \\ \\
              &amp;= \dfrac{\sum X_iY_i - n\bar{X}\bar{Y} - n\bar{X}\bar{Y} + n\bar{X}\bar{Y}}{\sum X_i^2 - n\bar{X}\bar{X} - n\bar{X}\bar{X} + n\bar{X}\bar{X}} \\ \\
              &amp;= \dfrac{\sum X_iY_i - \bar{X}\sum Y_i - \bar{Y}\sum X_i + \sum \bar{X}\bar{Y}}{\sum X_i^2 - 2\bar{X}\sum X_i + \sum \bar{X}^2} \\ \\
              &amp;= \dfrac{\sum (X_iY_i - \bar{X}Y_i - \bar{Y}X_i + \bar{X}\bar{Y})}{\sum (X_i^2 - 2\bar{X}X_i + \bar{X}^2)} \\ \\
              &amp;= \dfrac{\sum [X_i(Y_i - \bar{Y}) - \bar{X}(Y_i - \bar{Y})]}{\sum (X_i - \bar{X})^2} \\ \\
              &amp;= \dfrac{\sum [(X_i - \bar{X})(Y_i - \bar{Y})]}{\sum (X_i - \bar{X})^2} \\ \\
              &amp;= \dfrac{\sum x_iy_i}{\sum x_i^2} \\ \\
              \\

\hat{\beta_1} &amp;= \dfrac{\sum X_i^2\sum Y_i - \sum X_i \sum X_iY_i}{n\sum X_i^2 - (\sum X_i)^2} \\ \\
              &amp;= \bar{Y} - \hat{\beta_2}\bar{X}
\end{align} %]]&gt;&lt;/script&gt;

&lt;p&gt;其中，&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align}
\bar{X} &amp;= \dfrac{1}{n}\sum X_i \\
\bar{Y} &amp;= \dfrac{1}{n}\sum Y_i \\
x_i &amp;= (X_i - \bar{X}) \\
y_i &amp;= (Y_i - \bar{Y})
\end{align} %]]&gt;&lt;/script&gt;

&lt;p&gt;经过代数变换，&lt;script type=&quot;math/tex&quot;&gt;\hat{\beta_2}&lt;/script&gt; 还可以变换成如下形式&lt;/p&gt;

&lt;script type=&quot;math/tex; mode=display&quot;&gt;% &lt;![CDATA[
\begin{align}
\hat{\beta_2} &amp;= \dfrac{\sum x_iy_i}{\sum x_i^2} \\ \\
              &amp;= \dfrac{\sum x_iY_i}{\sum X_i^2 - n\bar{X}^2} \\ \\
              &amp;= \dfrac{\sum X_iy_i}{\sum X_i^2 - n\bar{X}^2}
\end{align} %]]&gt;&lt;/script&gt;

&lt;p&gt;这学期在上&lt;a href=&quot;https://book.douban.com/subject/5258945/&quot;&gt;计量经济学基础&lt;/a&gt;，在学到一元线性回归模型的参数估计时，别的推导过程都很简单，但是看到 &lt;script type=&quot;math/tex&quot;&gt;\hat{\beta_2}&lt;/script&gt; 的推导时卡了一下，因为书上直接由 &lt;script type=&quot;math/tex&quot;&gt;\dfrac{n\sum X_iY_i - \sum X_i \sum Y_i}{n\sum X_i^2 - (\sum X_i)^2}&lt;/script&gt; 推出了 &lt;script type=&quot;math/tex&quot;&gt;\dfrac{\sum [(X_i - \bar{X})(Y_i - \bar{Y})]}{\sum (X_i - \bar{X})^2}&lt;/script&gt;，我想了好久（比较愚笨），最后根据结果才反推出过程的，这也是促使我记录这篇博文的主要因素。&lt;/p&gt;

&lt;p&gt;文中若有疏漏之处，敬请在评论中指正。如果大神有更好的思路，也请在评论区交流，谢谢。&lt;/p&gt;
</description>
        <pubDate>Wed, 23 Mar 2016 23:29:30 +0800</pubDate>
        <link>http://shaofe.ng/%E6%95%B0%E5%AD%A6/%E4%B8%80%E5%85%83%E7%BA%BF%E6%80%A7%E5%9B%9E%E5%BD%92%E6%A8%A1%E5%9E%8B%E7%9A%84%E5%8F%82%E6%95%B0%E4%BC%B0%E8%AE%A1/</link>
        <guid isPermaLink="true">http://shaofe.ng/%E6%95%B0%E5%AD%A6/%E4%B8%80%E5%85%83%E7%BA%BF%E6%80%A7%E5%9B%9E%E5%BD%92%E6%A8%A1%E5%9E%8B%E7%9A%84%E5%8F%82%E6%95%B0%E4%BC%B0%E8%AE%A1/</guid>
        
        <category>计量经济学</category>
        
        <category>回归模型</category>
        
        <category>参数估计</category>
        
        
        <category>数学</category>
        
      </item>
    
      <item>
        <title>敢忍抢先成王师</title>
        <description>&lt;p&gt;张良，字子房，与萧何、韩信并称“汉初三杰”。《史记·留侯世家》主要叙述了张良的生平轶事，其描绘的张良谋略过人，是汉高祖刘邦建立汉朝并巩固统治的著名谋臣，因此被后人尊称为“谋圣”。&lt;/p&gt;

&lt;p&gt;《留侯世家》具体记载了张良辅助刘邦攻秦、退楚过程中，在一系列关键历史事件中献出的过人谋计，以及建立汉朝后，为稳定天下提出的种种解决方法。连刘邦都佩服说：“夫运筹于帷帐之中，决胜千里之外，吾不如子房。”本文限于篇幅，不分析张良的种种谋计，而是对大家耳熟能详的，《留侯世家》一开始就提出的“圯上纳履”这个故事，有一个新的解读。&lt;/p&gt;

&lt;p&gt;我们都听过“圯上纳履”这个故事，说的是张良散步到一座桥时，一位老先生把鞋扔到桥下并让张良去捡，张良捡回后又被要求帮助老先生穿上鞋。老先生很满意张良的态度，并与张良相约5日后平明再见。张良在前两次的迟到后，最后一次终于守时，老先生送了张良一本兵书后就走了。&lt;/p&gt;

&lt;p&gt;故事很简单，但是，如果我们从故事中得出的道理是：1、张良有礼貌，懂得尊重老人；2、老先生在教张良和人约会不要迟到。那么，这样读历史是没有收获的。《史记》是一本史学巨著，他所记载的每一个字，每一句话，每一起事件，都是经过司马迁的重重锤炼，能够体现出超越时代的历史道理的。我们应当跟着原文，再细细品读一遍“圯上纳履”，体会更深的道理。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;「良尝间从容步游下邳圯上，有一老父，衣褐，至良所，直堕其履圯下，顾谓良曰：“孺子，下取履！”」&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;一个衣着普通的老先生，故意走到张良面前，把鞋子扔到圯下，还态度很差的使唤张良，真是一件怪事！我们看一下张良是什么反应。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;「良鄂然，欲殴之。为其老，强忍，下取履。」&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;张良的第一反应很正常，符合年轻人的血气方刚，他想打这个老先生。但张良毕竟是张良，成大事的人，他忍住了，帮老先生拿鞋。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;「父曰：“履我！”良业为取履，因长跪履之。」&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;这就怪了！老先生要求张良帮他穿鞋时，张良什么都没说，就“履之”，“履之”不够，还要“跪履之”，“跪履之”还不够，还要“长跪履之”。张良做的这么极致是为什么？难道司马迁这么写是想告诉我们张良很能忍吗？其实，这里的意思是，张良既然一开始就忍了，那就一忍到底！苏轼在《留侯论》中对此写道：“人情有所不能忍者，匹夫见辱，拔剑而起，挺身而斗，此不足为勇也。天下有大勇者，卒然临之而不惊，无故加之而不怒。此其所挟持者甚大，而其志甚远也。”&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;「父以足受，笑而去。良殊大惊，随目之。父去里所，复还」&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;这一段很普通，但又不普通。老先生“笑而去”，说明老先生对张良“一忍到底”很满意，认为是可塑之才，第一关考验通过。最后两句很有意思，“父去里所，复还”，老先生都离开了一里了，再回来，张良还在这吗？张良知道老先生要回来，老先生知道张良还在这，神乎其神的。&lt;/p&gt;

&lt;p&gt;再看后面的三次约会。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;「五日平明，良往。父已先在」「五日鸡鸣，良往。父又先在」「五日，良夜未半往。有顷，父亦来，喜」&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;张良和老父约的就是“五日平明”，前两次张良知道了吗？没有，前两次都是在第五日，比预定时间“先”，但是比老先生“后”。张良第三次赴约，是在第四天的夜半，这样即使老先生还是先到，那也不能指责张良不守约，这叫“不后”。兵法有一招叫“先下手为强”，你知道先，敌人也知道先，只有掌握了绝对的先，出乎敌人意料的先，才能制胜。&lt;/p&gt;

&lt;p&gt;所以，“圯上纳履”这个故事，告诉我们的不仅仅是大家传诵的那么简单。通过上述的分析，我们知道老先生是想教给张良“忍”和“先”两个道理：忍，就一忍到底；先，就绝对的先。张良的这两个特质，是他十年后能“成王师”的基础条件。&lt;/p&gt;

&lt;p&gt;张良一生进退自如，谱写了富有传奇色彩的人生篇章。&lt;/p&gt;
</description>
        <pubDate>Sun, 06 Mar 2016 17:05:24 +0800</pubDate>
        <link>http://shaofe.ng/%E8%AF%BB%E5%8F%B2%E6%98%8E%E6%99%BA/%E6%95%A2%E5%BF%8D%E6%8A%A2%E5%85%88%E6%88%90%E7%8E%8B%E5%B8%88/</link>
        <guid isPermaLink="true">http://shaofe.ng/%E8%AF%BB%E5%8F%B2%E6%98%8E%E6%99%BA/%E6%95%A2%E5%BF%8D%E6%8A%A2%E5%85%88%E6%88%90%E7%8E%8B%E5%B8%88/</guid>
        
        <category>史记</category>
        
        <category>读后感</category>
        
        
        <category>读史明智</category>
        
      </item>
    
      <item>
        <title>更换博客托管商小记</title>
        <description>&lt;p&gt;2014年9月，Github针对学生用户推出了一个价值丰厚的大礼包，只要用自己学校的EDU邮箱通过认证就能获得这个礼包，里面包括Namecheap域名服务一年、DigitalOcean的100美元抵价券等超值礼品。借这个机会我购买了属于自己的域名timmyxu.me，以及DigitOcean上每个月5美元的VPS。利用这些工具，我曾经搭建过Wordpress这类的博客系统，也配置过Shadowsocks、VPN这类的科学上网工具，还用Github送的一年SSL证书给我的域名加上了HTTPS认证。&lt;/p&gt;

&lt;p&gt;最初的折腾劲过去后，到目前为止这个VPS主要是为我现在的这个静态博客和个人使用的VPN提供服务。前段时间正好看到了&lt;a href=&quot;http://blog.szm.me&quot;&gt;宋子明&lt;/a&gt;把自己的博客迁移到了&lt;a href=&quot;https://pages.github.com&quot;&gt;Github Pages&lt;/a&gt;上，我才突然想到除了用VPN之外，VPS仅仅在托管我的这个静态博客，并没有发挥到最大的价值。而我目前也没有更多的需求，尽管100美元的抵价券还没有用完，但为了防止以后想做一些新的事情，现在能节省就节省。因此我决定暂停DigitOcean上的VPS服务。&lt;/p&gt;

&lt;p&gt;暂停VPS服务意味着两个问题：第一是我的VPN服务也因此暂停，因为不少朋友同学都在用这个VPN，可能暂时不能为他们提供这些便利；第二是为我现在这个静态博客找到一个新家。上面说到Github提供了Github Pages的服务（Github真是良心！），每个用户可以免费为自己或者自己的项目建立静态网页。由于Github Pages完美支持Jekyll工具和自定义域名，配置极其简单，于是我就顺理成章地把博客迁过来啦。&lt;/p&gt;

&lt;p&gt;最后，我建立这个博客的初衷记录自己的学习收获和生活点滴，但是自今年4月建博以来一直没有发表过新的博文，实在是感到惭愧。这次博客迁移，希望自己能够坚持当初想法，不流于形式，不做表面之事，把想法实实在在落到笔头上。&lt;/p&gt;

&lt;p&gt;拭目以待！&lt;/p&gt;
</description>
        <pubDate>Sun, 13 Dec 2015 14:32:33 +0800</pubDate>
        <link>http://shaofe.ng/%E7%94%9F%E6%B4%BB%E9%9A%8F%E6%83%B3/%E6%9B%B4%E6%8D%A2%E5%8D%9A%E5%AE%A2%E6%89%98%E7%AE%A1%E5%95%86%E5%B0%8F%E8%AE%B0/</link>
        <guid isPermaLink="true">http://shaofe.ng/%E7%94%9F%E6%B4%BB%E9%9A%8F%E6%83%B3/%E6%9B%B4%E6%8D%A2%E5%8D%9A%E5%AE%A2%E6%89%98%E7%AE%A1%E5%95%86%E5%B0%8F%E8%AE%B0/</guid>
        
        <category>jekyll</category>
        
        
        <category>生活随想</category>
        
      </item>
    
      <item>
        <title>Progress Report on my Academic Career at BUAA</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;本文是我的口语课作业。记述大学生涯到目前为止的学业生涯进展报告。英文水平不佳，文中若有语法错误，敬请指正。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;TO&lt;/strong&gt;: Todd J. Sempel&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FROM&lt;/strong&gt;: 徐少峰 Shaofeng Xu&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DATE&lt;/strong&gt;: April 26, 2015&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SUBJECT&lt;/strong&gt;: Progress Report on my Academic Career at BUAA&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Work Completed&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Things are coming along very well in regards to my time here at BUAA.
First of all, I think I did a good job at my study. At each semester, although I was not top among students but always was the first 30% of them. That’s a far better grade than the goal I set to myself before entering the university.&lt;/p&gt;

&lt;p&gt;In the aspect of my social work, I was the monitor of my class from freshman to sophomore year. During my time as a monitor, I experienced and learned a lot from this share of responsibility. Whether solving the problems among classmates or informing our student counselor of concrete student’s life, I kept thinking, studying and practicing, and tried my best to do these things well.&lt;/p&gt;

&lt;p&gt;As an engineering student, I participated in several competitions in the past three years. Feng Ru Cup is the official annual scientific and technological competition in BUAA and I took part in it at sophomore year. Unfortunately, I did not win any reward for my project. However, I gained much competition experience from it. In addition to Feng Ru Cup, early in my sophomore, I joined in an algorithm competition which is ACM/ICPC regional in Nanjing and Hangzhou, and won two silver medals.&lt;/p&gt;

&lt;p&gt;I love playing table tennis, so I still represented our software college to participate in table tennis matches in freshman and sophomore years. Both of the two matches our team fell down in front of the top four.&lt;/p&gt;

&lt;p&gt;University life without being a member of a student club is incomplete. I enrolled in a club called AIESEC when I was a freshman. AIESEC is an international non-profit organization totally managed by students whose vision is “Peace and fulfillment of Humankind’s potential”. It’s really cool to touch various kinds of people around the world and strive for a same purpose.&lt;/p&gt;

&lt;p&gt;Last but not least experience in my university life, is that I did a voluntary work at Sunshine Village orphanage in the winter of my sophomore year. It is quite a unforgettable experience. I rethought about the significant of family, love, fate and equality after I finished the voluntary work.&lt;/p&gt;

&lt;p&gt;Overall, I’m satisfied with my experience since I entered the BUAA.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Work Scheduled/Planned&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I still have several things that must be done before I am able to graduate.
The most important thing to do is my graduation project. After a four-year study at my major in BUAA, the best thing to check my learning outcomes is a perfect graduation project. I think it’s my next year’s focus.&lt;/p&gt;

&lt;p&gt;Meanwhile, I plan to apply for an internship later this year. As we all know, lore from books needs to be practiced in real production environment.&lt;/p&gt;

&lt;p&gt;Keep going!&lt;/p&gt;
</description>
        <pubDate>Sun, 26 Apr 2015 17:02:48 +0800</pubDate>
        <link>http://shaofe.ng/%E7%94%9F%E6%B4%BB%E9%9A%8F%E6%83%B3/Progress-Report/</link>
        <guid isPermaLink="true">http://shaofe.ng/%E7%94%9F%E6%B4%BB%E9%9A%8F%E6%83%B3/Progress-Report/</guid>
        
        <category>english</category>
        
        
        <category>生活随想</category>
        
      </item>
    
      <item>
        <title>基于Jekyll的静态博客生成指南</title>
        <description>&lt;h2 id=&quot;前言&quot;&gt;前言&lt;/h2&gt;

&lt;p&gt;本文主要介绍著名的静态博客生成器 Jekyll 的基本使用方法。不同于 &lt;a href=&quot;http://cn.wordpress.org&quot;&gt;WordPress&lt;/a&gt; 等博客系统，Jekyll 生成的站点无需依赖数据库，所有页面都由 Jekyll 静态生成，用户只需使用 Markdown 等标记语言撰写文章并重新生成即可。本站即基于 Jekyll 搭建。&lt;/p&gt;

&lt;p&gt;首先简单介绍一下 Jekyll。&lt;/p&gt;

&lt;h2 id=&quot;简介&quot;&gt;简介&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Jekyll 是一个简单的博客形态的静态站点生成器。它有一个模版目录，其中包含原始文本格式的文档，通过 Markdown（或者 Textile） 以及 Liquid 转化成一个完整的可发布的静态网站，你可以发布在任何你喜爱的服务器上。Jekyll 也可以运行在 GitHub Page 上，也就是说，你可以使用 GitHub 的服务来搭建你的项目页面、博客或者网站，而且是完全免费的。		——&lt;a href=&quot;http://jekyllcn.com&quot;&gt;Jekyll中文官方网站&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;特性&quot;&gt;特性&lt;/h3&gt;

&lt;p&gt;如上文所说，Jekyll 具有三大特性：简单，静态，博客形态。具体解释如下：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;简单：无需数据库，没有评论功能，没有频繁的版本更新——仅仅关注你的内容。&lt;/li&gt;
  &lt;li&gt;静态：利用 Markdown（或 Textile）等标记语言，Liquid 模板语言，和 HTML &amp;amp; CSS 构建可发布的静态网站。&lt;/li&gt;
  &lt;li&gt;博客形态：支持 URL 自定义，支持文章分类，支持单页面，可以自定义博客布局。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;目录结构&quot;&gt;目录结构&lt;/h3&gt;

&lt;p&gt;Jekyll 的核心其实是一个文本转换引擎。它的概念其实就是：你用你最喜欢的标记语言来写文章，可以是 Markdown，也可以是 Textile，或者就是简单的 HTML，然后 Jekyll 就会帮你套入一个或一系列的布局中。在整个过程中你可以设置 URL 路径，你的文本在布局中的显示样式等等。这些都可以通过纯文本编辑来实现，最终生成的静态页面就是你的成品了。&lt;/p&gt;

&lt;p&gt;一个基本的 Jekyll 网站的目录结构一般是像这样的：&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;.
├── _config.yml
├── _drafts
|	├──begin-with-the-crazy-ideas.textile
|	└──on-simplicity-in-technology.markdown
├──_includes
|	├── footer.html
|	└── header.html
├── _layouts
|	├── default.html
|	└── post.html
├── _posts
|	├── 2007-10-29-why-every-programmer-should-play-nethack.markdown
|	└── 2009-04-26-barcamp-boston-4-roundup.markdown
├── _site
└── index.html&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;ol&gt;
  &lt;li&gt;_config.yml: 配置文件，例如站点 title，permalink 的格式等在这个文件中配置，在布局文件中可以用liquid语言进行调用。&lt;/li&gt;
  &lt;li&gt;_drafts: 存放草稿的文件夹。&lt;/li&gt;
  &lt;li&gt;_includes: 你可以加载这些包含部分到你的布局或者文章中以方便重用。可以用这个标签  &lt;code class=&quot;highlighter-rouge&quot;&gt;{\% include header.html %}&lt;/code&gt; （去掉转义符号\，下同）来把文件 _includes/header.html 包含进来。&lt;/li&gt;
  &lt;li&gt;_layouts: 是包裹在文章外部的模板。布局可以在 &lt;strong&gt;YAML&lt;/strong&gt; 头信息中根据不同文章进行选择。 下一章中将对此进行介绍。标签 &lt;code class=&quot;highlighter-rouge&quot;&gt;{\{ content }\}&lt;/code&gt; 可以将 content 插入页面中。&lt;/li&gt;
  &lt;li&gt;_posts: 这里存放的是你的文章。文件格式很重要，必须要符合: YEAR-MONTH-DAY-title.MARKUP。permalinks 可以在文章中通过 YAML 自己定制，但是数据和标记语言都是根据文件名来确定的。&lt;/li&gt;
  &lt;li&gt;_site:  Jekyll 生成后的静态网站就存在这个文件夹中。将此文件夹中的内容上传至你的服务器，即可访问。&lt;/li&gt;
  &lt;li&gt;index.html 等其他文件: 如果这些文件含有 YAML 头信息，那么Jekyll会将其转化成静态页面。以 &lt;code class=&quot;highlighter-rouge&quot;&gt;.html&lt;/code&gt;，&lt;code class=&quot;highlighter-rouge&quot;&gt;.markdown&lt;/code&gt;，&lt;code class=&quot;highlighter-rouge&quot;&gt;.md&lt;/code&gt; 或者 &lt;code class=&quot;highlighter-rouge&quot;&gt;.textile&lt;/code&gt; 结尾的也会被转换。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;本章对 Jekyll 进行了一些简单的介绍，若想详细了解其他方面，请访问 Jekyll 官方网站（&lt;a href=&quot;http://jekyllcn.com&quot;&gt;中文&lt;/a&gt;，&lt;a href=&quot;http://jekyllrb.com&quot;&gt;英文&lt;/a&gt;）。&lt;/p&gt;

&lt;h2 id=&quot;使用指南&quot;&gt;使用指南&lt;/h2&gt;

&lt;p&gt;本指南是博主搭建本站时的步骤总结，供初次使用 Jekyll 的同学提供一点思路。主要从安装、配置和部署三个方面来介绍。&lt;/p&gt;

&lt;h3 id=&quot;安装&quot;&gt;安装&lt;/h3&gt;

&lt;p&gt;由于最终只需将 _site 文件夹内的内容部署至服务器，所以我们在本地安装 Jekyll 并配置生成博客，然后部署即可。&lt;/p&gt;

&lt;p&gt;这里博主使用的环境是&lt;strong&gt;Mac OS X 10.10&lt;/strong&gt;，Linux 下操作类似，官方不推荐使用 Windows 运行 Jekyll。&lt;/p&gt;

&lt;p&gt;安装使用 RubyGems，操作过程很简单，打开命令行，输入以下命令：&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;~ &lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gem &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;jekyll
~ &lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;jekyll new my-awesome-site
~ &lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;my-awesome-site
~/my-awesome-site &lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;jekyll serve
&lt;span class=&quot;c&quot;&gt;# =&amp;gt; Now browse to http://localhost:4000&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;打开你的浏览器，在地址栏中输入 http://localhost:4000 即可访问由 Jekyll 生成的静态站点！&lt;/p&gt;

&lt;h3 id=&quot;配置说明&quot;&gt;配置说明&lt;/h3&gt;

&lt;p&gt;好了，第一步成功后，我们可以访问由 Jekyll 生成的一个默认的站点，为了让站点更加符合自己的个性与审美，下面我们对站点进行一些配置。&lt;/p&gt;

&lt;h4 id=&quot;站点设置&quot;&gt;站点设置&lt;/h4&gt;

&lt;h5 id=&quot;_configyml&quot;&gt;&lt;strong&gt;_config.yml&lt;/strong&gt;&lt;/h5&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;_config.yml&lt;/code&gt;文件是站点全局配置文件。在此文件中我们可以修改自己的站点 title，description，permalink 格式等全局变量，以及标记语言解释器和一些其他的设置。Jekyll 默认的配置见&lt;a href=&quot;http://jekyllrb.com/docs/configuration/#default-configuration]&quot;&gt;此处&lt;/a&gt;。&lt;/p&gt;

&lt;p&gt;在样式模板中可以调用此文件中的变量，使用方法是用 liquid 语言进行调用，如 &lt;code class=&quot;highlighter-rouge&quot;&gt;{\{ site.title }\}&lt;/code&gt;，父属性是 &lt;strong&gt;site&lt;/strong&gt;。&lt;/p&gt;

&lt;h5 id=&quot;yaml&quot;&gt;&lt;strong&gt;YAML&lt;/strong&gt;&lt;/h5&gt;

&lt;p&gt;正是 YAML 头信息开始让 Jekyll 变的很酷。任何只要包含 YAML 头信息的文件在 Jekyll 中都能被当做一个特殊的文件来处理。头信息必须在文件的开始部分，并且需要按照 YAML 的格式写在两行三虚线之间。下面是一个基本的例子：&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;---
layout: post
title: Blogging Like a Hacker
---&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;在 YAML 头信息中，你可以使用已经定义好的全局变量，如 &lt;code class=&quot;highlighter-rouge&quot;&gt;layout&lt;/code&gt;，&lt;code class=&quot;highlighter-rouge&quot;&gt;permalink&lt;/code&gt; 等，也可以自定义变量，如 &lt;code class=&quot;highlighter-rouge&quot;&gt;title&lt;/code&gt;，使其可以在样式模板中使用这个变量。调用自定义变量方法是 &lt;code class=&quot;highlighter-rouge&quot;&gt;{\{page.title}\}&lt;/code&gt;，父属性是 &lt;strong&gt;page&lt;/strong&gt;。&lt;/p&gt;

&lt;h4 id=&quot;自定义样式&quot;&gt;自定义样式&lt;/h4&gt;

&lt;p&gt;Jekyll 默认的模板很简洁，也很漂亮。本站基于默认模板样式作出了一点改动，例如超链接样式，header 配色，边栏布局等。&lt;/p&gt;

&lt;p&gt;Jekyll默认模板中样式文件主要是 css 文件夹中的 main.scss，_sass 文件夹中的 base.scss 和 layout.scss。&lt;/p&gt;

&lt;p&gt;main.scss 文件主要设定了如 width，margin 等基本值，base.scss 文件对 HTML 基本元素进行了 reset，layout.scss 文件是对自定义 class，id 等进行样式设置。博主主要修改的就是 layout.scss 文件。有关 CSS 样式，以及动态样式语言 SCSS 的相关知识，可自行 Google 学习。&lt;/p&gt;

&lt;h4 id=&quot;评论功能&quot;&gt;评论功能&lt;/h4&gt;

&lt;p&gt;作为不依赖数据库的静态博客系统，Jekyll 自然是没有文章评论功能，如果想在自己的博文中引入评论功能，可以引入公共的评论平台。目前常用的有 Disqus 和多说。本站用的是 Disqus。&lt;/p&gt;

&lt;p&gt;具体设置方法很简单：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;在 &lt;a href=&quot;http://disqus.com&quot;&gt;Disqus 官网&lt;/a&gt; 注册账号并登陆，点击右上角&lt;code class=&quot;highlighter-rouge&quot;&gt;Settings - Add Disqus To Site&lt;/code&gt;按钮；&lt;/li&gt;
  &lt;li&gt;填写你站点的相关信息，完成创建；&lt;/li&gt;
  &lt;li&gt;设置你的评论框，包括登陆限制，语言等，保存设置；&lt;/li&gt;
  &lt;li&gt;点击 &lt;code class=&quot;highlighter-rouge&quot;&gt;install&lt;/code&gt;，生成一段js代码，复制并粘贴到 Jekyll 中你想让评论出现的地方即可（本站为 &lt;code class=&quot;highlighter-rouge&quot;&gt;_layout/post.html&lt;/code&gt; 文件中末端）；&lt;/li&gt;
  &lt;li&gt;在文章的 YAML 信息中添加 &lt;code class=&quot;highlighter-rouge&quot;&gt;comments: true&lt;/code&gt;。&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;注意&lt;/strong&gt;：Disqus的评论框设置改变后，只对新调用了评论接口的文章有效，对之前的文章无效，即旧文章评论框还是改动前的设置。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4 id=&quot;分类目录标签&quot;&gt;分类目录&amp;amp;标签&lt;/h4&gt;

&lt;p&gt;Jekyll 提供了分类（category）和标签（tag）的全局变量，我们可以在自己文章的 YAML 头信息里加上相关信息，如下：&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;---
layout: post
title:  &quot;基于Jekyll的静态博客生成初级指南&quot;
categories: 技术杂谈
tags: jekyll
---&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;如果想在文章正文显示这些分类和标签，那么在文章的模板中（&lt;code class=&quot;highlighter-rouge&quot;&gt;_layout/post.html&lt;/code&gt;）相应位置添加调用即可。&lt;/p&gt;

&lt;p&gt;不过我们可能会有这样的需求：&lt;em&gt;需要在单独一个页面显示某个分类或者某个标签下所有的文章&lt;/em&gt;。这时，我们引入&lt;strong&gt;插件&lt;/strong&gt;功能。&lt;/p&gt;

&lt;p&gt;Jekyll 支持插件功能，你可以很容易的加入自己的代码。插件由 &lt;code class=&quot;highlighter-rouge&quot;&gt;ruby&lt;/code&gt; 语言写成。&lt;/p&gt;

&lt;p&gt;插件的安装很简单：在博客根下目录建立 _plugins 文件夹，插件放在这里即可。 Jekyll 运行之前，会加载此目录下所有以 *.rb 结尾的文件。&lt;/p&gt;

&lt;p&gt;为了满足上面提到的需求，本站使用了 Github 用户 recurser 提供的插件 &lt;a href=&quot;https://github.com/recurser/jekyll-plugins&quot;&gt;jekyll-plugins&lt;/a&gt;。
该插件提供了生成单个分类页面的功能，使用方法如下：&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;下载项目；&lt;/li&gt;
  &lt;li&gt;将 &lt;code class=&quot;highlighter-rouge&quot;&gt;generate_categories.rb&lt;/code&gt; 复制到站点的 &lt;code class=&quot;highlighter-rouge&quot;&gt;_plugins&lt;/code&gt; 文件夹中，将 &lt;code class=&quot;highlighter-rouge&quot;&gt;_layout&lt;/code&gt; 中的 &lt;code class=&quot;highlighter-rouge&quot;&gt;category_index.html&lt;/code&gt; 复制到站点 &lt;code class=&quot;highlighter-rouge&quot;&gt;_layout&lt;/code&gt; 文件夹中，这两个文件分别是插件和样式；&lt;/li&gt;
  &lt;li&gt;在需要显示分类列表的地方添加如下代码&lt;/li&gt;
&lt;/ol&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
	{\% for category in site.categories %}
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;a&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;href=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/categories/{\{category|first}\}/&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
		&lt;span class=&quot;nt&quot;&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
			{\{ category|first }\} 
			|
			{\{ category|last|size}\}
		&lt;span class=&quot;nt&quot;&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
	{\% endfor %}
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;其中，&lt;code class=&quot;highlighter-rouge&quot;&gt;site.categories&lt;/code&gt;存放站点的分类集合，&lt;code class=&quot;highlighter-rouge&quot;&gt;category|first&lt;/code&gt;为分类名，&lt;code class=&quot;highlighter-rouge&quot;&gt;category|last|size&lt;/code&gt;为该分类下文章数目。该分类所有文章列表的页面 URL 为 &lt;code class=&quot;highlighter-rouge&quot;&gt;/categories/{\{category|first}\}/&lt;/code&gt;。&lt;/p&gt;

&lt;p&gt;对于标签，只需将插件中的 category 关键字替换为 tag 即可。&lt;/p&gt;

&lt;p&gt;更多插件，请查看&lt;a href=&quot;http://jekyllrb.com/docs/plugins/#available-plugins&quot;&gt;官方文档&lt;/a&gt;。&lt;/p&gt;

&lt;h3 id=&quot;部署方法&quot;&gt;部署方法&lt;/h3&gt;

&lt;p&gt;常用的有两种部署方法。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Github Pages 提供免费托管服务，参考&lt;a href=&quot;http://jekyllcn.com/docs/github-pages/&quot;&gt;这里&lt;/a&gt;的指南。&lt;/li&gt;
  &lt;li&gt;可以部署到自己的 VPS 上，利用 rsync 命令将本地生成后的  _site 文件夹内容上传至网站根目录即可。示例：&lt;code class=&quot;highlighter-rouge&quot;&gt;rsync -avz _site/. &amp;lt;name&amp;gt;@&amp;lt;IP&amp;gt;:/var/www/html/&lt;/code&gt;。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;结语&quot;&gt;结语&lt;/h2&gt;

&lt;p&gt;Jekyll 还有很多功能诸如分页、数学公式的支持等，会在将来本站更新到这些功能时，另开一篇文章说明。&lt;/p&gt;

&lt;p&gt;当然，还有很多其他非常优秀的静态网站生成器，&lt;a href=&quot;https://www.staticgen.com&quot;&gt;这里&lt;/a&gt;列出了其中一部分。&lt;a href=&quot;http://szm.me&quot;&gt;宋子明&lt;/a&gt;的&lt;a href=&quot;http://szm.me/build-a-static-blog-using-nanoc/&quot;&gt;这篇博文&lt;/a&gt;介绍了Nanoc使用方法，大家可以参考。&lt;/p&gt;

</description>
        <pubDate>Tue, 14 Apr 2015 21:41:03 +0800</pubDate>
        <link>http://shaofe.ng/%E6%8A%80%E6%9C%AF%E6%9D%82%E8%B0%88/%E5%9F%BA%E4%BA%8EJekyll%E7%9A%84%E9%9D%99%E6%80%81%E5%8D%9A%E5%AE%A2%E7%94%9F%E6%88%90%E5%88%9D%E7%BA%A7%E6%8C%87%E5%8D%97/</link>
        <guid isPermaLink="true">http://shaofe.ng/%E6%8A%80%E6%9C%AF%E6%9D%82%E8%B0%88/%E5%9F%BA%E4%BA%8EJekyll%E7%9A%84%E9%9D%99%E6%80%81%E5%8D%9A%E5%AE%A2%E7%94%9F%E6%88%90%E5%88%9D%E7%BA%A7%E6%8C%87%E5%8D%97/</guid>
        
        <category>jekyll</category>
        
        
        <category>技术杂谈</category>
        
      </item>
    
  </channel>
</rss>
