質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

0回答

344閲覧

openInMapsでマップを起動してルート検索後、元のアプリに戻ると"タッチしてナビに戻る"表示が出て、アプリの画面が下にズレる。

t.harima

総合スコア55

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2018/06/28 06:43

元アプリの"検索" ボタンを押して、openInMapsでマップアプリを起動してルート検索後、"出発"ボタンを押し、左上の元のアプリに戻るボタン"<"を押して元のアプリに戻ると、画面の上部に"タッチしてナビに戻る"という表示がされて画面が下にズレる。
元アプリの画面上部に表示される"タッチしてナビに戻る"という表示をしないようにしたいです。
長いソースで申し訳ありませんが、よろしくお願いいたします。

swift4

1import UIKit 2import MapKit 3import CoreLocation 4 5 6class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate, UIPickerViewDelegate, UIPickerViewDataSource { 7 8 var myMapView : MKMapView! 9 var myLocationManager : CLLocationManager! 10 var userLocation : CLLocationCoordinate2D! 11 var cmlkLocation : CLLocationCoordinate2D! 12 13 var cmlkPickerView : UIPickerView! 14 let pickerViewHeight : CGFloat = 160 15 16 var pickerToolBar : UIToolbar! 17 let toolBarHeight : CGFloat = 40.0 18 19 var cmlkValues : NSArray = ["下から選んでください。","県庁前 事業所","呉服町 事業所"] 20 var cmlkRow : Int = 0 21 var cmlkAddress : String = "" 22 23 var cmlkPin : MKPointAnnotation! 24 25 var selectButton : UIButton! 26 var searchButton : UIButton! 27 28 // 縮尺. 29 var zoomInit : Bool = true 30 let ZOOM_INIT_LAT : Double = 0.0177655284856755 31 let ZOOM_INIT_LON : Double = 0.0160932555655791 32 var myCoordingRegion : MKCoordinateRegion! 33 var mySpan : MKCoordinateSpan! 34 35 override func viewDidLoad() { 36 super.viewDidLoad() 37 // Do any additional setup after loading the view, typically from a nib. 38 39 let devMaxWidth : CGFloat = self.view.bounds.width 40 let devMaxHeight : CGFloat = self.view.bounds.height 41 42 myMapView = MKMapView() 43 myLocationManager = CLLocationManager() 44 userLocation = CLLocationCoordinate2D() 45 cmlkLocation = CLLocationCoordinate2D() 46 selectButton = UIButton() 47 searchButton = UIButton() 48 49 // UIPickerViewを生成. 50 cmlkPickerView = UIPickerView() 51 pickerToolBar = UIToolbar() 52 cmlkPin = MKPointAnnotation() 53 54 selectButton.frame = CGRect(x: 0.0, y: 20.0, width: devMaxWidth, height: 40.0) 55 pickerToolBar.frame = CGRect(x: 0.0, y: 60.0, width: devMaxWidth, height: toolBarHeight) 56 cmlkPickerView.frame = CGRect(x: 0.0, y: 60.0 + toolBarHeight, width: devMaxWidth, height: pickerViewHeight) 57 myMapView.frame = CGRect(x: 0.0, y: 60.0, width: devMaxWidth, height: devMaxHeight - 60.0) 58 searchButton.frame = CGRect(x: devMaxWidth / 5.0 * 4.0, y: devMaxHeight - 40.0, width: devMaxWidth / 5.0, height: 40.0) 59 60 61 myMapView.delegate = self 62 myLocationManager.delegate = self 63 // Delegateを設定する. 64 cmlkPickerView.delegate = self 65 // DataSourceを設定する. 66 cmlkPickerView.dataSource = self 67 // ToolBarを設定する. 2018.06.26.add 68 pickerToolBar.backgroundColor = UIColor.cyan 69 pickerToolBar.isHidden = true 70 let flexible = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil) 71 let doneBtn = UIBarButtonItem(title: "完了", style: .plain, target: self, action: #selector(self.onClickButton)) 72 pickerToolBar.items = [flexible,doneBtn] 73 74 75 // 位置情報取得の許可状況を確認 76 let status = CLLocationManager.authorizationStatus() 77 78 if(status == CLAuthorizationStatus.notDetermined) { 79 print("didChangeAuthorizationStatus:(status)"); 80 self.myLocationManager.requestAlwaysAuthorization() 81 } 82 83 myLocationManager.desiredAccuracy = kCLLocationAccuracyBest 84 myLocationManager.distanceFilter = 300 85 myLocationManager.startUpdatingLocation() 86 87 myMapView.setCenter(self.myMapView.userLocation.coordinate, animated: true) 88 myMapView.userTrackingMode = MKUserTrackingMode.none 89 myMapView.showsUserLocation = true 90 91 selectButton.backgroundColor = UIColor.yellow 92 selectButton.setTitle("事業所を選択", for: .normal) 93 selectButton.setTitleColor(UIColor.black, for: .normal) 94 selectButton.addTarget(self, action: #selector(self.onClickButton), for: .touchUpInside) 95 96 searchButton.backgroundColor = UIColor.green 97 searchButton.setTitle("検索", for: .normal) 98 searchButton.setTitleColor(UIColor.black, for: .normal) 99 searchButton.addTarget(self, action: #selector(self.onSearch), for: .touchUpInside) 100 101 cmlkPickerView.backgroundColor = UIColor.cyan 102 cmlkPickerView.layer.shadowOpacity = 0.5 103 cmlkPickerView.isHidden = true 104 105 // Viewに追加する. 106 self.view.addSubview(myMapView) 107 self.view.addSubview(selectButton) 108 self.view.addSubview(pickerToolBar) 109 self.view.addSubview(cmlkPickerView) 110 self.view.addSubview(searchButton) 111 112 } 113 114 func numberOfComponents(in pickerView: UIPickerView) -> Int { 115 return 1 116 } 117 118 // pickerに表示する行数を返すデータソースメソッド. (実装必須) 119 func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 120 return cmlkValues.count 121 } 122 123 // pickerに表示する値を返すデリゲートメソッド. 124 func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 125 return cmlkValues[row] as? String 126 } 127 128 // pickerが選択された際に呼ばれるデリゲートメソッド. 129 func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 130 cmlkRow = row 131 if cmlkRow == 0 { 132 selectButton.setTitle("事業所を選択", for: .normal) 133 } else if cmlkRow == 1 { 134 cmlkAddress = "福岡市博多区千代4-1-33" 135 cmlkLocation.latitude = 33.602905 136 cmlkLocation.longitude = 130.414481 137 selectButton.setTitle("(cmlkValues[cmlkRow])", for: .normal) 138 } else if cmlkRow == 2 { 139 cmlkAddress = "福岡市博多区上呉服町11-16" 140 cmlkLocation.latitude = 33.598882 141 cmlkLocation.longitude = 130.410745 142 selectButton.setTitle("(cmlkValues[cmlkRow])", for: .normal) 143 } else { 144 cmlkAddress = "" 145 } 146 } 147 148 @objc func onClickButton() { 149 if cmlkPickerView.isHidden == true { 150 cmlkPickerView.isHidden = false 151 pickerToolBar.isHidden = false 152 // セット済みのピンを削除 153 self.myMapView.removeAnnotations(self.myMapView.annotations) 154 } else { 155 cmlkPickerView.isHidden = true 156 pickerToolBar.isHidden = true 157 if cmlkRow != 0 { 158 // セット済みのピンを削除 159 self.myMapView.removeAnnotations(self.myMapView.annotations) 160 161 pinStand() 162 163 } 164 } 165 } 166 167 @objc func onSearch(){ 168 // Pickerを隠す 169 cmlkPickerView.isHidden = true 170 pickerToolBar.isHidden = true 171 // 選択されていない時は、終了する。 172 if cmlkRow == 0 { return } 173 174 pinStand() 175 176 let myPlacemark = MKPlacemark(coordinate: (self.cmlkPin?.coordinate)!) 177 let myMapItem = MKMapItem(placemark: myPlacemark) 178 myMapItem.name = self.cmlkValues[self.cmlkRow] as? String 179 let myLaunchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeTransit, MKLaunchOptionsMapTypeKey: MKMapType.standard.rawValue] as [String: Any] 180 myMapItem.openInMaps(launchOptions: myLaunchOptions) 181 } 182 183 func pinStand(){ 184 //地図にピンを立てる。 185 self.cmlkPin.title = self.cmlkValues[self.cmlkRow] as? String 186 self.cmlkPin.subtitle = self.cmlkAddress 187 self.cmlkPin.coordinate = CLLocationCoordinate2D(latitude: cmlkLocation.latitude, longitude: cmlkLocation.longitude) 188 self.myMapView.addAnnotation(self.cmlkPin) 189 } 190 191 // 位置情報取得に成功したときに呼び出されるデリゲート. 192 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){ 193 userLocation = CLLocationCoordinate2DMake((manager.location?.coordinate.latitude)!, (manager.location?.coordinate.longitude)!) 194 195 if zoomInit == true { 196 myMapView.centerCoordinate = CLLocationCoordinate2DMake( userLocation.latitude, userLocation.longitude) 197 198 var centerLocation = CLLocationCoordinate2D() 199 centerLocation.latitude = self.myMapView.region.center.latitude 200 centerLocation.longitude = self.myMapView.region.center.longitude 201 202 self.myCoordingRegion = self.myMapView.region 203 self.myCoordingRegion.center = centerLocation 204 205 mySpan = MKCoordinateSpan(latitudeDelta: ZOOM_INIT_LAT, longitudeDelta: ZOOM_INIT_LON) 206 let myRegion : MKCoordinateRegion = MKCoordinateRegion(center: myMapView.centerCoordinate, span: mySpan) 207 myMapView.region = myRegion 208 209 myMapView.setRegion(myRegion, animated: true) 210 zoomInit = false 211 } 212 } 213 214 // 位置情報取得に失敗した時に呼び出されるデリゲート. 215 func locationManager(_ manager: CLLocationManager,didFailWithError error: Error){ 216 print("locationManager error") 217 } 218 219 // Regionが変更された時に呼び出されるメソッド. 220 func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) { 221 } 222 223 override func didReceiveMemoryWarning() { 224 super.didReceiveMemoryWarning() 225 // Dispose of any resources that can be recreated. 226 } 227} 228

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問