我正在学习如何使用新的Swift语言(只有Swift,没有Objective-C).要做到这一点,我想用map(MKMapView)做一个简单的视图.我想查找并更新用户的位置(例如在Apple Map应用程序中).
我试过了,但没有发生任何事:
import MapKit
import CoreLocation
class MapView : UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var map: MKMapView!
var locationManager: CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
if (CLLocationManager.locationServicesEnabled())
{
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
}
}
Run Code Online (Sandbox Code Playgroud)
请你帮助我好吗?
我有一个View.在这个观点中,我有一个Container View.在ContainerView我有一个按钮.
当我触摸ContainerView的按钮时,我想要隐藏ContainerView.
我想做那样的事情:
class ContainerView: UIViewController {
@IBAction func closeContainerViewButton(sender: AnyObject) {
//I try this : self.hidden = false
//or this : self.setVisibility(self.INVISIBLE)
}
}
Run Code Online (Sandbox Code Playgroud)
知道怎么做?
我在法国,当我尝试新func locationManager功能时,我的地图视图在旧金山找到了我.任何的想法?
override func viewDidLoad() {
super.viewDidLoad()
if (CLLocationManager.locationServicesEnabled())
{
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
let location = locations[locations.count-1] as CLLocation
let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.map.setRegion(region, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
我正在使用模拟器.