Skip to content

Commit 28ffe64

Browse files
author
cyper
committed
v2.0 complete review view
1 parent dea9738 commit 28ffe64

1 file changed

Lines changed: 88 additions & 1 deletion

File tree

README.md

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# FoodPinDemo
22
My exercises while reading the appcoda book.
33

4-
![](foodpin_v1.png)
4+
![](polished-foodpin.png)
55

66
## Some notes
77

@@ -103,6 +103,93 @@ title = restaurant.name
103103
3. tableView.rowHeight = UITableViewAutomaticDimension, 从iOS10开始, 这已经是默认值
104104
4. 这时console会有个layout warning, 解决办法是给这个cell中包含的那个stack view设置top和bottom约束(之前已经给它设定了leading/trailing和center vertically的约束,但是对于自适应大小的cell来说还不够)
105105

106+
### 圆形button
107+
1. title=blank, image=check, (type=system, tint=white设置按钮的颜色)
108+
2. 点pin按钮,设置top=8,right=8,width=28,height=28
109+
110+
### 全屏背景
111+
1. drag a new view controller
112+
2. drag image view onto it, resize to full screen
113+
3. add missing constraints, 但是Xcode8.1上这个选项是灰的, 最后用了reset to suggested constraints
114+
115+
### 半屏窗口
116+
1. container view: drag a view object onto the image view(x=53, y=40, 269*420)
117+
118+
### 右上角关闭按钮
119+
1. Drag a button(top=-13, right=-12, 28*28), title=blank, image=cross
120+
2. 在前一屏中加入`@IBAction func close(segue: UIStoryboardSegue) {}`这句代码告诉Xcode这个viewController可以被unwind
121+
3. Ctrl drag this close button to the exit button on this review scene, and select `closeWithSegue:`
122+
123+
### 让全屏背景模糊
124+
125+
在viewDidLoad中加入
126+
127+
```swift
128+
let blurEffect = UIBlurEffect(style: .dark)
129+
let blurEffectView = UIVisualEffectView(effect: blurEffect)
130+
blurEffectView.frame = view.bounds
131+
backgroundImageView.addSubview(blurEffectView)
132+
133+
```
134+
就是给ImageView加上一个大小相同的subview, 上面代码中第三行view变量是所有UIViewController都有的, 表示这个ViewController管理的顶层view对象.
135+
136+
### Container view大小变换(scaleX)
137+
怎么将view的大小变成0? 大小值用`CGAffineTransform`表示
138+
139+
1. 大小为0:CGAffineTransform(scaleX: 0, y: 0)
140+
2. 原始大小及位置:CGAffineTransform.indentiy
141+
3. 在viewDidLoad中将view的transform属性设置为0
142+
4. 在viewDIdAppear中将view的transform属性设置为原始值.
143+
144+
145+
简单动画
146+
147+
```swift
148+
UIView.animate(withDuration: 0.3, animations: {
149+
self.containerView.transform = CGAffineTransform.identity
150+
})
151+
```
152+
153+
Spring动画(UIView.animate多加些参数)
154+
155+
```swift
156+
UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 0.3, initialSpringVelocity: 0.2, options: .curveEaseOut, animations: {
157+
self.containerView.transform = CGAffineTransform.identity
158+
}, completion: nil)
159+
```
160+
161+
### 组合变换scale + translate(viewDidLoad)
162+
163+
```swift
164+
let scaleTransform = CGAffineTransform(scaleX: 0, y: 0)
165+
let translateTransform = CGAffineTransform(translationX: 0, y: -1000)
166+
let combineTransform = scaleTransform.concatenating(translateTransform)
167+
containerView.transform = combineTransform
168+
```
169+
170+
CGAffineTransform(translationX:y:)中的x, y都是相对于目标原始位置的偏移量, 并不是相对屏幕左上角.
171+
172+
### 3 more unwind segue(with identifier)
173+
在detailViewController中加入`@IBAction func ratingButtonTapped(segue: UIStoryboardSegue) {}`
174+
分别拖动review界面上的三个评价按钮到exit button, 全部选择ratingButtonTappedWithSegue:, 这样在outline中会多出三个unwind segue, 设定它们的identifier为great/good/dislike
175+
176+
177+
```swift
178+
@IBAction func ratingButtonTapped(segue: UIStoryboardSegue) {
179+
if let rating = segue.identifier {
180+
restaurant.isVisited = true
181+
182+
switch rating {
183+
case "great": restaurant.rating = "love it."
184+
// ...
185+
default: break
186+
}
187+
}
188+
189+
tableView.reloadData()
190+
}
191+
```
192+
106193
### Keywords
107194

108195
1. 取选中行的行号: tableView.indexPathForSelectedRow

0 commit comments

Comments
 (0)