今天顺利完成了Demo 3,完结撒花~~~
我做了如下工作:
05 Map View
06 Photo Picker
07 Finished
首先看Map View:
Bar上有两个item: Locations和User。
其中Locations记录的是历史定位,User记录的是当前定位
(我是这么理解的,但是因为模拟器上定位有误,所有位置都是同一个坐标,因此不知道这样理解对不对)
我们希望:
The pins are now green and the callout has a custom button.
我们还希望:Map所在的navigation bar可以和模拟器的状态栏无缝链接。(**)
实现代码如下:
extension MapViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView,
viewFor annotation: MKAnnotation) -> MKAnnotationView? {
// 1
guard annotation is Location else {
return nil
}
// 2
let identifier = "Location"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
if annotationView == nil {
let pinView = MKPinAnnotationView(annotation: annotation,reuseIdentifier: identifier)
// 3
pinView.isEnabled = true
pinView.canShowCallout = true
pinView.animatesDrop = false
pinView.pinTintColor = UIColor(red: 0.32, green: 0.82,
blue: 0.4, alpha: 1)
// 4
let rightButton = UIButton(type: .detailDisclosure)
rightButton.addTarget(self,
action: #selector(showLocationDetails),
for: .touchUpInside)
pinView.rightCalloutAccessoryView = rightButton
annotationView = pinView
}
if let annotationView = annotationView {
annotationView.annotation = annotation
// 5
let button = annotationView.rightCalloutAccessoryView as! UIButton
if let index = locations.index(of: annotation as! Location) {
button.tag = index
}
}
return annotationView
}
1. 在info.plist中加入项,开启权限
2. 开启权限后,初次使用时询问如下:
3. Add Photo,Delete Photo, Edit Photo, Cell中添加Image View用来显示照片。
最后是界面优化:
1. Aspect Fit 和 Aspect Fill 的区别:
2. 原图片像素过高,势必会造成存储的浪费,我们需要对原图片形变后再存入ImageView
3. 将图片以圆形边框呈现
4. 将背景调成夜间黑色
5. tap location的开始动画
遇到的问题:
tap location 和 get location 指向了同一个功能。
原因: 没有设置delegate.
Demo4 开启了 20/290 的进度
------- 凌晨MARK,醒来再补