画面を遷移した先でMKMapViewを表示したいと思ってます。
MapViewControllerに配置したMapViewをタップすると、MapViewControllerが閉じられてViewControllerに戻ってしまいます。
なんででしょうか?
よろしくお願いいたしますm(__)m
Swift
1import UIKit 2 3class ViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 8 let mapInfoButton: UIButton = UIButton(frame: CGRectMake(0,0,250,50)) 9 mapInfoButton.backgroundColor = UIColor.redColor() 10 mapInfoButton.layer.masksToBounds = true 11 mapInfoButton.setTitle("Map",forState:.Normal) 12 mapInfoButton.layer.cornerRadius = 10.0 13 mapInfoButton.layer.position = CGPoint(x: self.view.bounds.width/2 , y:self.view.bounds.height / 8 * 3) 14 mapInfoButton.tag = 1 15 mapInfoButton.addTarget(self, action: "onClickMyButton:", forControlEvents: .TouchUpInside) 16 self.view.addSubview(mapInfoButton) 17 self.view.backgroundColor = UIColor.whiteColor() 18 } 19 20 internal func onClickMyButton(sender: UIButton){ 21 let mySecondViewController: UIViewController = MapViewController() 22 mySecondViewController.modalTransitionStyle = UIModalTransitionStyle.PartialCurl 23 self.presentViewController(mySecondViewController, animated: true, completion: nil) 24 } 25 26 override func didReceiveMemoryWarning() { 27 super.didReceiveMemoryWarning() 28 } 29}
Swift
1import UIKit 2import MapKit 3 4class MapViewController: UIViewController, MKMapViewDelegate { 5 6 var myMapView: MKMapView! 7 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 11 myMapView = MKMapView() 12 myMapView.frame = CGRectMake(0,0,self.view.bounds.width , self.view.bounds.height / 2) 13 myMapView.delegate = self 14 let myLatitude: CLLocationDegrees = 37.331741 15 let myLongitude: CLLocationDegrees = -122.030333 16 let center: CLLocationCoordinate2D = CLLocationCoordinate2DMake(myLatitude, myLongitude) 17 myMapView.setCenterCoordinate(center, animated: true) 18 let mySpan: MKCoordinateSpan = MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01) 19 let myRegion: MKCoordinateRegion = MKCoordinateRegionMake(center, mySpan) 20 myMapView.region = myRegion 21 22 self.view.addSubview(myMapView) 23 self.view.backgroundColor = UIColor.whiteColor() 24 } 25 26 func mapView(mapView: MKMapView!, regionDidChangeAnimated animated: Bool) { 27 } 28 29 override func didReceiveMemoryWarning() { 30 super.didReceiveMemoryWarning() 31 } 32}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/09/08 02:44