Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在ViewDidDisplay中重新定义插座mkmapview_Ios_Swift_Memory Management_Mkmapview_Mapkit - Fatal编程技术网

Ios 在ViewDidDisplay中重新定义插座mkmapview

Ios 在ViewDidDisplay中重新定义插座mkmapview,ios,swift,memory-management,mkmapview,mapkit,Ios,Swift,Memory Management,Mkmapview,Mapkit,我有一个基于选项卡的应用程序。其中一个选项卡包含MKMapview 当我第一次启动这个应用程序时,我的内存大约是44MB 当我切换到带有地图的选项卡时,它会跳到84MB 此外,我还根据客户机的要求添加了两个放大和缩小按钮 只需点击两次zoomIn按钮,它就会跳到104,然后点击两次zoomOut按钮,它就会跳到112 我想在ViewDiddiss中取消显示我的地图视图,以便释放一些内存: override func viewDidDisappear(animated: Bool) {

我有一个基于选项卡的应用程序。其中一个选项卡包含MKMapview

当我第一次启动这个应用程序时,我的内存大约是44MB

当我切换到带有地图的选项卡时,它会跳到84MB

此外,我还根据客户机的要求添加了两个放大和缩小按钮

只需点击两次zoomIn按钮,它就会跳到104,然后点击两次zoomOut按钮,它就会跳到112

我想在ViewDiddiss中取消显示我的地图视图,以便释放一些内存:

override func viewDidDisappear(animated: Bool) {
        super.viewDidDisappear(animated)
        self.mapView = nil
}
然后,我需要将setUpMaps func更改为在ViewDidDisplay而不是viewDidLoad上调用。详情如下:

 func setUpMaps(){
        locManager = CLLocationManager()
        locManager.delegate = self
        locManager.startUpdatingLocation()
        self.mapView.delegate = self
        self.mapView.pitchEnabled = true
        self.mapView.showsBuildings = true

        let latitude:CLLocationDegrees = Prefs.latitude
        let longitude: CLLocationDegrees = Prefs.longitude
        let theRegion:MKCoordinateRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake(latitude,longitude), MKCoordinateSpanMake(0.9, 0.9))
        self.mapView.setRegion(theRegion, animated: true)
        let thePoint = MKPointAnnotation()
        thePoint.coordinate = CLLocationCoordinate2DMake(Prefs.latitude as CLLocationDegrees, Prefs.longitude as CLLocationDegrees)
        thePoint.title = "Your registered location"
        self.mapView.addAnnotation(thePoint)
        addRadiusCircle(CLLocation(latitude: Prefs.latitude as CLLocationDegrees, longitude: Prefs.longitude as CLLocationDegrees), radiusParam: CLLocationDistance(Double(Prefs.radius)))
    }
显然,这会在第二次崩溃,因为mapView为零。所以我需要再次给它一个值。比如:

var mapView = MKMapView()
但我将mapView定义为一个出口:

@IBOutlet weak var mapView: MKMapView!
是否有任何方法可以将var mapView与viewDidAppear func中的my outlet重新关联?或者我应该完全放弃这个插座,以编程方式创建mapView吗?如果以编程方式定义,我应该使用弱var吗

缩放功能:

@IBAction func zoomIn(sender: UIButton) {
    let span = MKCoordinateSpan(latitudeDelta: mapView.region.span.latitudeDelta/2, longitudeDelta: mapView.region.span.longitudeDelta/2)
    mapView.setRegion(MKCoordinateRegion(center: mapView.region.center, span: span), animated: true)
}

@IBAction func zoomOut(sender: UIButton) {
    let span = MKCoordinateSpan(latitudeDelta: mapView.region.span.latitudeDelta*2, longitudeDelta: mapView.region.span.longitudeDelta*2)
    mapView.setRegion(MKCoordinateRegion(center: mapView.region.center, span: span), animated: true)
}

你能展示一下你是怎么变焦的吗?对大内存增加感兴趣。你试过在消失时删除所有的符号吗?@zcui93我在我的函数中添加了放大和缩小功能。但值得一提的是,当我在地图上捏和缩放时(不使用我的按钮),我看到了同样的增长!这实际上有点糟糕,因为在进行收缩和缩放时,您可以一次完成tgreater缩放,而不是点击一个按钮,每次只能放大/缩小一定数量time@user2363025您可以轻松地将地图添加为子视图,而不是将地图放在UIView类型的XIB keep和MapContainer中并在其上添加地图,然后从SuperView中删除。您是在设备中还是在模拟器中检查此行为?@iphone在ViewDidDisplay上以编程方式将地图添加为子视图?您的意思是,是吗?是否应将其定义为弱var?我正在检查一台iPhone设备6S@user2363025是,将其添加到ViewDidDisplay。。