有没有办法拍摄mapView的截图并包含折线?我相信我需要在MKSnapShotter返回的图像上绘制CGPoint,但我不确定如何这样做.
目前的代码
func takeSnapshot(mapView: MKMapView, withCallback: (UIImage?, NSError?) -> ()) {
let options = MKMapSnapshotOptions()
options.region = mapView.region
options.size = mapView.frame.size
options.scale = UIScreen.main().scale
let snapshotter = MKMapSnapshotter(options: options)
snapshotter.start() { snapshot, error in
guard snapshot != nil else {
withCallback(nil, error)
return
}
if let image = snapshot?.image{
withCallback(image, nil)
for coordinate in self.area {
image.draw(at:snapshot!.point(for: coordinate))
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我目前正在将我的swift 2.3代码转换为swift 3,我在以下行中收到上述错误:
setSharedPassword(nil, account: account, completion: completion)
Run Code Online (Sandbox Code Playgroud)
适当的解决方案是否只是用""代替nil?当我这样做时,错误消失了.我正在寻找解释.请帮忙.
我尝试导入 watchOS 的 SpeechKit 框架并收到错误。有什么办法可以和手表一起使用吗?当我导入 Speechkit 框架时出现错误,提示“没有这样的模块语音”
import WatchKit
import Foundation
import Speech
class SpeechInterfaceController: WKInterfaceController, SFSpeechRecognizerDelegate {
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
Run Code Online (Sandbox Code Playgroud)
}
我创建了一个名为RegistrationButton的自定义UIButton.我目前正在尝试允许用户在三个按钮之间进行选择.选择按钮后,背景颜色和文本将发生变化.以下是IBAction的外观:
@IBAction func didTapBUtton(_ sender: UIButton) {
switch sender {
case studentButton:
studentButton.selected()
professionalButton.notSelected()
entrepreneurhsip.notSelected()
break
case professionalButton:
studentButton.notSelected()
professionalButton.selected()
entrepreneurhsip.notSelected()
break
case entrepreneurhsipButton:
studentButton.notSelected()
professionalButton.notSelected()
entrepreneurhsip.selected()
break
default:
break
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的自定义UIButton类的方法:
import UIKit
class RegistrationButton: UIButton {
override func awakeFromNib() {
super.awakeFromNib()
addBorder()
}
required init(coder:NSCoder) {
super.init(coder:coder)!
}
func addBorder(){
self.layer.borderColor = UIColor.white.cgColor
self.layer.borderWidth = 1
}
func selected(){
self.backgroundColor = .white
self.setTitleColor(UIColor(red:67,green:204,blue:144,alpha:1), for: .normal)
}
func notSelected(){
self.backgroundColor = UIColor(red:67,green:204,blue:144,alpha:1)
self.setTitleColor(UIColor.white, for: .normal)
}
Run Code Online (Sandbox Code Playgroud)
}