|
1 |
| -# SwiftUI-Tutorials |
2 |
| -A code example and translation project of SwiftUI. |
| 1 | + |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <a href="https://github.com/WillieWangWei"><img src="https://img.shields.io/badge/language-swift-orange.svg"></a> |
| 5 | + <a href="https://github.com/WillieWangWei"><img src="https://img.shields.io/github/repo-size/WillieWangWei/SwiftUI-Tutorials.svg"></a> |
| 6 | + <a href="https://github.com/WillieWangWei/SwiftUI-Tutorials/blob/master/LICENSE"><img src="https://img.shields.io/github/license/WillieWangWei/SwiftUI-Tutorials.svg"></a> |
| 7 | +</p> |
| 8 | + |
| 9 | +> **构建示例项目需要以下环境:** |
| 10 | +> |
| 11 | +> * macOS 10.15 beta 或更高 |
| 12 | +> * Xcode 11.0 beta 或更高 |
| 13 | +
|
| 14 | +# 概述 |
| 15 | + |
| 16 | +此项目为 [SwiftUI Tutorials](https://developer.apple.com/tutorials/swiftui) 的翻译及代码示例,具体内容请翻阅: |
| 17 | + |
| 18 | +**🎉 [SwiftUI 教程(中文)](https://github.com/WillieWangWei/SwiftUI-Tutorials/wiki)** |
| 19 | + |
| 20 | +> **觉得不错?给个 Star 或 Follow 👌** |
| 21 | +
|
| 22 | +## 调整 |
| 23 | + |
| 24 | +### 图片 |
| 25 | + |
| 26 | +为了优化阅读体验,所有图片加上了 `#000000` `50%` `10 Blur` 的阴影。 |
| 27 | + |
| 28 | +### 视频 |
| 29 | + |
| 30 | +由于 `GitHub Wiki` 的限制,所有视频已转码成 `GIF ` 。 |
| 31 | + |
| 32 | +### 代码 |
| 33 | + |
| 34 | +在实际编码中,由于本地环境和官方教程不一致,导致部分方法的声明和调用方式、代码风格等与官方教程有细微出入,例如: |
| 35 | + |
| 36 | +官方教程: |
| 37 | + |
| 38 | +``` |
| 39 | +... |
| 40 | +struct MapView: UIViewRepresentable { |
| 41 | + func makeUIView(context: Context) -> MKMapView { |
| 42 | + MKMapView(frame: .zero) |
| 43 | + } |
| 44 | +} |
| 45 | +... |
| 46 | +``` |
| 47 | + |
| 48 | +这里的 `UIViewRepresentable` 是一个协议,它的声明中包含一个 `associatedtype` : |
| 49 | + |
| 50 | +``` |
| 51 | +/// The type of `UIView` to be presented. |
| 52 | +associatedtype UIViewType : UIView |
| 53 | +``` |
| 54 | + |
| 55 | +在开发中,给此 `associatedtype` 赋值后 Xcode 对方法的签名补全会有变化,最终写作: |
| 56 | + |
| 57 | +``` |
| 58 | +... |
| 59 | +struct MapView : UIViewRepresentable { |
| 60 | + |
| 61 | + typealias UIViewType = MKMapView |
| 62 | + |
| 63 | + func makeUIView(context: UIViewRepresentableContext<MapView>) -> MKMapView { |
| 64 | + return MKMapView(frame: .zero) |
| 65 | + } |
| 66 | +} |
| 67 | +... |
| 68 | +``` |
| 69 | + |
| 70 | +如此修改不再一一列举,只需记得**此类修改不会改变原教程的构建结果**即可,不必过于纠结。 |
| 71 | + |
| 72 | +## License |
| 73 | + |
| 74 | +This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/WillieWangWei/SwiftUI-Tutorials/blob/master/LICENSE) file for details. |
0 commit comments