2014-11-13 1 views
2

사용자가 longPress (UILongPressGestureRecognizer 포함)를 수행 할 때 Pin을 추가하려고하는데 작동하지 않습니다. 그러나 더 큰 문제는 다음과 같습니다.지도가 더 이상 표시되지 않습니다. 왜지도가 사라 졌는가?GestureRecognizer를 추가하면 MapView가 더 이상 작동하지 않습니다.

당신은 프로젝트 파일을 찾을 수 here

--------------------------- ViewController.swift ----- ---------------------------

{ 

import UIKit 
import MapKit 

class ViewController: UIViewController, MKMapViewDelegate { 

@IBOutlet var theMapView: MKMapView! 
@IBOutlet var theTextfield: UITextField! 

@IBOutlet var theLabel: UILabel! 

@IBAction func theButton(sender: UIButton) { 
    theLabel.text = "Swift-App schreibt \(theTextfield.text)" 
    theTextfield.resignFirstResponder() 
} 


override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    // Position 
    var latitude:CLLocationDegrees = 48.399193 
    var longitude:CLLocationDegrees = 9.993341 
    // Zoomfaktor 
    var latDelta:CLLocationDegrees = 0.01 
    var longDelta:CLLocationDegrees = 0.01 
    // 
    var theSpan:MKCoordinateSpan = MKCoordinateSpanMake(latDelta,longDelta) 



    // Koordinaten der Kirche 
    var churchLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude) 
    // Zentrum und Kartenausschnitt 
    var theRegion:MKCoordinateRegion = MKCoordinateRegionMake(churchLocation, theSpan) 


    // LongTap definieren 
    let longpress = UILongPressGestureRecognizer(target: theMapView, action: "actionPin:") 
    longpress.minimumPressDuration = 1.0 
    longpress.numberOfTouchesRequired = 1 
    longpress.allowableMovement = 100 
    theMapView.addGestureRecognizer(longpress) 


    // Karte anzeigen 
    theMapView.setRegion(theRegion,animated:false) 

    // Pin setzen 
    var theUlmMinsterAnnotation = MKPointAnnotation() 
    theUlmMinsterAnnotation.coordinate = churchLocation 
    theUlmMinsterAnnotation.title = "Ulmer Münster" 
    theUlmMinsterAnnotation.subtitle = " Untertitel" 

    theMapView.addAnnotation(theUlmMinsterAnnotation) 
} 

func actionPin(gestureRecognizer:UIGestureRecognizer) { 
    var touchpoint = gestureRecognizer.locationInView(self.theMapView) 
    var newCoord:CLLocationCoordinate2D=theMapView.convertPoint(touchpoint, toCoordinateFromView: self.theMapView) 
    var newAnnotation = MKPointAnnotation() 
    newAnnotation.coordinate = newCoord 
    newAnnotation.title = "Fingertipp" 
    newAnnotation.subtitle = "Untertitel" 
    theMapView.addAnnotation(newAnnotation) 
} 

}} 
+0

와 프로젝트는 관련 코드를 게시 할 수 있다면 당신은 더 좋은 반응을 얻을 수 있습니다. 당신이하고있는 일은 그렇게 복잡하지 않아서 질문에 맞지 않습니다. – Acey

+0

@Acey done. 감사! – Rico30

+0

스토리 보드/xib를 사용하여'theMapView'를 뷰 컨트롤러에 추가하고 있습니까? – thelaws

답변

0

지도 크기가 {0,0}이며 사용자가 아무 것도 사용하지 않기 때문에 억누르다. 여기

확인 부분 업데이트 https://dl.dropboxusercontent.com/u/19438780/test1-v2.zip

+0

고맙습니다. 이제지도가 보입니다. 제약은 무엇인가를 배우는 중요한 주제 인 것처럼 보인다. :)하지만 왜 길쭉한 탭이 인식되지 않았는지 알았습니까? – Rico30

+0

MKMapView에 긴 탭을 추가하는 것은 그리 간단하지 않습니다. 이미 다른 UIGestureRecognizer가 있기 때문에 ... 하나의 솔루션이 될 수 있습니다 .. MKMapView를 서브 클래 싱하는 것 http://stackoverflow.com/a/21124351/1702413 ... 이러한 기존 제스처를 "감지"하고 모두에게 GestureRecognizerToFail을 요구합니다. – TonyMkenu

관련 문제