teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

コメント修正

2017/02/28 10:38

投稿

_utah
_utah

スコア20

title CHANGED
File without changes
body CHANGED
@@ -113,14 +113,14 @@
113
113
  ```
114
114
 
115
115
  ```swift
116
- // mapViewがさな時にタップされたら拡大して後ろ側
116
+ // childViewを縮小して前面
117
117
  func ChangeMapView(sender: AnyObject) {
118
118
  self.mapView.frame = CGRect(x: 100, y: 1, width: 400, height: 400)
119
119
  self.childView.frame = CGRect(x: 1, y: 1, width: 200, height: 200)
120
120
  self.parentView.bringSubviewToFront(self.childView)
121
121
  }
122
122
 
123
- // childViewがさい時にタップされたら拡大して後ろ側
123
+ // mapViewを縮小して前面
124
124
  func ChangeChildView(sender: AnyObject) {
125
125
  self.childView.frame = CGRect(x: 1, y: 1, width: 400, height: 400)
126
126
  self.mapView.frame = CGRect(x: 1, y: 1, width: 200, height: 200)

3

解決したコードを追加

2017/02/28 10:38

投稿

_utah
_utah

スコア20

title CHANGED
File without changes
body CHANGED
@@ -78,4 +78,52 @@
78
78
  self.mapView.frame = CGRect(x: 1, y: 1, width: 200, height: 200)
79
79
  self.parentView.bringSubviewToFront(self.mapView)
80
80
  }
81
+ ```
82
+
83
+
84
+
85
+
86
+ ###解決したコード
87
+ ```swift
88
+ // 親のビュー
89
+ @IBOutlet weak var parentView: UIView!
90
+
91
+ // 描画順を変更したいビュー
92
+ var mapView : MKMapView! = MKMapView()
93
+ var childView : UIView! = UIView()
94
+ ```
95
+
96
+ ```swift
97
+
98
+ override func viewWillAppear(animated : Bool) {
99
+ super.viewWillAppear(animated)
100
+
101
+ // サブビューに追加
102
+ parentView.addSubview(self.mapView)
103
+ parentView.addSubview(self.childView)
104
+
105
+ // 大きさの初期値
106
+ self.mapView.frame = CGRect(x: 0,y: 0,width: 100,height: 100)
107
+ self.childView.frame = CGRect(x: 110,y: 0,width: 100,height: 100)
108
+
109
+ // タップできるようにする
110
+ self.mapView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ChangeMapView)))
111
+ self.childView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ChangeChildView)))
112
+ }
113
+ ```
114
+
115
+ ```swift
116
+ // mapViewが小さな時にタップされたら拡大して後ろ側に
117
+ func ChangeMapView(sender: AnyObject) {
118
+ self.mapView.frame = CGRect(x: 100, y: 1, width: 400, height: 400)
119
+ self.childView.frame = CGRect(x: 1, y: 1, width: 200, height: 200)
120
+ self.parentView.bringSubviewToFront(self.childView)
121
+ }
122
+
123
+ // childViewが小さい時にタップされたら拡大して後ろ側に
124
+ func ChangeChildView(sender: AnyObject) {
125
+ self.childView.frame = CGRect(x: 1, y: 1, width: 400, height: 400)
126
+ self.mapView.frame = CGRect(x: 1, y: 1, width: 200, height: 200)
127
+ self.parentView.bringSubviewToFront(self.mapView)
128
+ }
81
129
  ```

2

コードの追記

2017/02/28 10:36

投稿

_utah
_utah

スコア20

title CHANGED
File without changes
body CHANGED
@@ -62,4 +62,20 @@
62
62
  swift2.3
63
63
  Xcode7.3.1
64
64
 
65
- ![イメージ説明](629368124fde45c48d096b5e0a1a37b0.png)
65
+ ![イメージ説明](629368124fde45c48d096b5e0a1a37b0.png)
66
+
67
+
68
+ アドバイスを受け修正したコードになります。
69
+ ```swift
70
+ @IBAction func ChangeMapView(sender: AnyObject) {
71
+ self.mapView.frame = CGRect(x: 100, y: 1, width: 400, height: 400)
72
+ self.childView.frame = CGRect(x: 1, y: 1, width: 200, height: 200)
73
+ self.parentView.bringSubviewToFront(self.childView)
74
+ }
75
+
76
+ @IBAction func ChangeChildView(sender: AnyObject) {
77
+ self.childView.frame = CGRect(x: 1, y: 1, width: 400, height: 400)
78
+ self.mapView.frame = CGRect(x: 1, y: 1, width: 200, height: 200)
79
+ self.parentView.bringSubviewToFront(self.mapView)
80
+ }
81
+ ```

1

階層がわかりにくいので、画像追加

2017/02/28 08:47

投稿

_utah
_utah

スコア20

title CHANGED
File without changes
body CHANGED
@@ -60,4 +60,6 @@
60
60
 
61
61
  ###補足情報(言語/FW/ツール等のバージョンなど)
62
62
  swift2.3
63
- Xcode7.3.1
63
+ Xcode7.3.1
64
+
65
+ ![イメージ説明](629368124fde45c48d096b5e0a1a37b0.png)