Skip to content

Commit cfa6f43

Browse files
author
lixian
committed
m
1 parent 05ee989 commit cfa6f43

File tree

1 file changed

+37
-42
lines changed

1 file changed

+37
-42
lines changed

Porting Your iOS App to macOS.md

+37-42
Original file line numberDiff line numberDiff line change
@@ -1503,43 +1503,42 @@
15031503
}
15041504
</pre>
15051505
<p>
1506-
Nothing too crazy here. You’re simply doing the following:
1506+
这里没有太多累赘的东西。你只需去完成下列的事情:
15071507
</p>
15081508
<ol>
15091509
<li>
1510-
Creating a new beer.
1510+
创建一个新的啤酒。
15111511
</li>
15121512
<li>
1513-
Inserting the beer into the model.
1513+
将啤酒插入到model中。
15141514
</li>
15151515
<li>
1516-
Inserting a new row into the table.
1516+
为table插入一个新的行。
15171517
</li>
15181518
<li>
1519-
Selecting the row of the new beer.
1519+
选择新啤酒所在的这行。
15201520
</li>
15211521
</ol>
15221522
<p>
1523-
You might have even noticed that, like in iOS, you need to call
1523+
你货主注意到了这点,就像在iOS中一样,你需要在插入新的行之前调用
15241524
<code>
15251525
beginUpdates()
15261526
</code>
1527-
and
1527+
15281528
<code>
15291529
endUpdates()
15301530
</code>
1531-
before inserting the new row. See, you really do know a lot about macOS
1532-
already!
1531+
。所以说,你其实早已懂得了关于macOS的很多的内容!
15331532
</p>
15341533
<h3>
1535-
Removing Entries
1534+
移除条目
15361535
</h3>
15371536
<p>
1538-
To remove a beer, add the below code for
1537+
为了移除一瓶啤酒,添加下列的代码到
15391538
<code>
15401539
removeBeer(\_:)
15411540
</code>
1542-
:
1541+
中:
15431542
</p>
15441543
<pre lang="swift" class="language-swift hljs"><span class="hljs-meta">@IBAction</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">removeBeer</span><span class="hljs-params">(<span class="hljs-number">_</span> sender: Any)</span></span> {
15451544
<span class="hljs-keyword">guard</span> <span class="hljs-keyword">let</span> beer = selectedBeer,
@@ -1561,46 +1560,44 @@
15611560
}
15621561
</pre>
15631562
<p>
1564-
Once again, very straightforward code:
1563+
依然是非常直接的代码:
15651564
</p>
15661565
<ol>
15671566
<li>
1568-
If a beer is selected, you remove it from the model.
1567+
如果已选中一个啤酒,就从model中移除它。
15691568
</li>
15701569
<li>
1571-
Reload the table view, and select the first available beer.
1570+
重载table view,选择第一瓶可用的啤酒。
15721571
</li>
15731572
</ol>
15741573
<h3>
1575-
Handling Images
1574+
处理图片
15761575
</h3>
15771576
<p>
1578-
Remember how
1577+
记得
15791578
<em>
15801579
Image Wells
15811580
</em>
1582-
have the ability to accept an image dropped on them? Change
1581+
拥有接收拖拽到它上面的图片的能力么?将
15831582
<code>
15841583
imageChanged(\_:)
15851584
</code>
1586-
to:
1585+
的方法修改为:
15871586
</p>
15881587
<pre lang="swift" class="language-swift hljs"><span class="hljs-meta">@IBAction</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">imageChanged</span><span class="hljs-params">(<span class="hljs-number">_</span> sender: NSImageView)</span></span> {
15891588
<span class="hljs-keyword">guard</span> <span class="hljs-keyword">let</span> image = sender.image <span class="hljs-keyword">else</span> { <span class="hljs-keyword">return</span> }
15901589
selectedBeer?.saveImage(image)
15911590
}
15921591
</pre>
15931592
<p>
1594-
And you thought it was going to be hard! Apple has taken care of all the
1595-
heavy lifting for you, and provides you with the image dropped.
1593+
你以为这可能会很难!但苹果早已为你负责处理了所有繁重的工作,并将接收拖拽来的图片的能力赐予了你。
15961594
</p>
15971595
<p>
1598-
On the flip side to that, you’ll need to do a bit more work to handle
1599-
user’s picking the image from within your app. Replace
1596+
但另一方面,你需要做很多工作,来方便用户从你的app中选取图片。将
16001597
<code>
16011598
selectImage()
16021599
</code>
1603-
with:
1600+
方法替换为:
16041601
</p>
16051602
<pre lang="swift" class="language-swift hljs"><span class="hljs-meta">@IBAction</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">selectImage</span><span class="hljs-params">(<span class="hljs-number">_</span> sender: Any)</span></span> {
16061603
<span class="hljs-keyword">guard</span> <span class="hljs-keyword">let</span> window = view.window <span class="hljs-keyword">else</span> { <span class="hljs-keyword">return</span> }
@@ -1628,37 +1625,36 @@
16281625
}
16291626
</pre>
16301627
<p>
1631-
The above code is how you use
1628+
上述代码实现了你使用
16321629
<code>
16331630
NSOpenPanel
16341631
</code>
1635-
to select a file. Here’s what’s happening:
1632+
来选取一个文件的过程。以下是详细步骤:
16361633
</p>
16371634
<ol>
16381635
<li>
1639-
You create an
1636+
创建一个
16401637
<code>
16411638
NSOpenPanel
16421639
</code>
1643-
, and configure its settings.
1640+
,并配置它的设置。
16441641
</li>
16451642
<li>
1646-
In order to allow the user to choose only pictures, you set the allowed
1647-
file types to your preferred image formats.
1643+
为了让用户只可以选择图片,你将允许的文件类型设置为你所需的文件格式。
16481644
</li>
16491645
<li>
1650-
Present the sheet to the user.
1646+
展示这个sheet给用户。
16511647
</li>
16521648
<li>
1653-
Save the image if the user selected one.
1649+
如果用户选择了一张图片的话,保存它。
16541650
</li>
16551651
</ol>
16561652
<p>
1657-
Finally, add the code that will save the data model in
1653+
最后,在
16581654
<code>
16591655
updateBeer(\_:)
16601656
</code>
1661-
:
1657+
中添加保存数据model的代码:
16621658
</p>
16631659
<pre lang="swift" class="language-swift hljs"><span class="hljs-meta">@IBAction</span> <span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">updateBeer</span><span class="hljs-params">(<span class="hljs-number">_</span> sender: Any)</span></span> {
16641660
<span class="hljs-comment">// 1.</span>
@@ -1679,26 +1675,25 @@
16791675
}
16801676
</pre>
16811677
<p>
1682-
Here’s what you added:
1678+
上述代码:
16831679
</p>
16841680
<ol>
16851681
<li>
1686-
You ensure the beer exists, and update its properties.
1682+
确认啤酒是存在的,并更新它的property。
16871683
</li>
16881684
<li>
1689-
Update the table view to reflect any names changes in the table.
1685+
更新table view以在table上反映任何名称的变化。
16901686
</li>
16911687
<li>
1692-
Save the data to the disk.
1688+
保存数据到磁盘上。
16931689
</li>
16941690
</ol>
16951691
<p>
1696-
You’re all set! Build and run the app, and start adding beers. Remember,
1697-
you’ll need to select
1692+
你已经全部设定完毕!运行app,然后添加啤酒。记住你需要选择
16981693
<em>
16991694
Update
17001695
</em>
1701-
to save your data.
1696+
来更新你的数据。
17021697
</p>
17031698
<p>
17041699
<img src="https://koenig-media.raywenderlich.com/uploads/2017/05/BeerTracker-mac-UI-Beers.png"
@@ -1707,7 +1702,7 @@
17071702
sizes="(max-width: 600px) 100vw, 600px">
17081703
</p>
17091704
<h3>
1710-
Final Touches
1705+
最后的接触
17111706
</h3>
17121707
<p>
17131708
You’ve learned a lot about the similarities and differences between iOS

0 commit comments

Comments
 (0)