質問編集履歴
3
コードを修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -258,6 +258,16 @@
|
|
258
258
|
|
259
259
|
// ここでTwoViewControllerに画面遷移したい
|
260
260
|
|
261
|
+
|
262
|
+
|
263
|
+
let nextVC = TwoViewController()
|
264
|
+
|
265
|
+
let naviVC = UINavigationController(rootViewController: nextVC)
|
266
|
+
|
267
|
+
self.present(naviVC, animated: true, completion: nil)
|
268
|
+
|
269
|
+
// これだとTabBarが隠れてしまう
|
270
|
+
|
261
271
|
}
|
262
272
|
|
263
273
|
|
2
コードを修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -218,6 +218,20 @@
|
|
218
218
|
|
219
219
|
|
220
220
|
|
221
|
+
// ボタンを追加
|
222
|
+
|
223
|
+
var jumpButton : UIButton!
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
jumpButton = UIButton(frame: CGRect(x: (self.view.frame.size.width) / 2, y: (self.view.frame.size.height) / 2, width: (self.view.frame.size.width) / 4 , height: (self.view.frame.size.height) / 4 ))
|
228
|
+
|
229
|
+
jumpButton.setTitle("Text", for: .normal)
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
jumpButton.addTarget(self, action: #selector(jumpView), for: .touchUpInside)
|
234
|
+
|
221
235
|
// Do any additional setup after loading the view.
|
222
236
|
|
223
237
|
}
|
@@ -234,6 +248,20 @@
|
|
234
248
|
|
235
249
|
|
236
250
|
|
251
|
+
// ボタンが押された時の動作
|
252
|
+
|
253
|
+
@objc func jumpView(sender: UIButton)
|
254
|
+
|
255
|
+
{
|
256
|
+
|
257
|
+
print ("ボタンが押されました")
|
258
|
+
|
259
|
+
// ここでTwoViewControllerに画面遷移したい
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
|
237
265
|
|
238
266
|
|
239
267
|
/*
|
1
コードを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -25,3 +25,343 @@
|
|
25
25
|
Xcode,9.2
|
26
26
|
|
27
27
|
Swidt 4
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
```Swift4
|
32
|
+
|
33
|
+
AppDelegate.swift
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
import UIKit
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
@UIApplicationMain
|
42
|
+
|
43
|
+
class AppDelegate: UIResponder, UIApplicationDelegate {
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
var window: UIWindow?
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
|
54
|
+
|
55
|
+
{
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
//ViewControllerのインスタンスを生成。
|
60
|
+
|
61
|
+
let tab1 = OneViewController()
|
62
|
+
|
63
|
+
let tab2 = TwoViewController()
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
//タブを配列に代入
|
74
|
+
|
75
|
+
let myTabs = NSArray(objects:tab1,tab2)
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
//UITabControlerのインスタンスを生成
|
80
|
+
|
81
|
+
let tabbarController = UITabBarController()
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
//tabbarControllerにタブを設定する
|
86
|
+
|
87
|
+
tabbarController.setViewControllers(myTabs as? [UIViewController], animated: false)
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
//rootにtabbarControllerを設定
|
92
|
+
|
93
|
+
self.window!.rootViewController = tabbarController
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
//表示
|
98
|
+
|
99
|
+
self.window!.makeKeyAndVisible()
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
// Override point for customization after application launch.
|
104
|
+
|
105
|
+
return true
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
func applicationWillResignActive(_ application: UIApplication) {
|
112
|
+
|
113
|
+
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
114
|
+
|
115
|
+
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
func applicationDidEnterBackground(_ application: UIApplication) {
|
122
|
+
|
123
|
+
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
124
|
+
|
125
|
+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
func applicationWillEnterForeground(_ application: UIApplication) {
|
132
|
+
|
133
|
+
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
func applicationDidBecomeActive(_ application: UIApplication) {
|
140
|
+
|
141
|
+
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
func applicationWillTerminate(_ application: UIApplication) {
|
148
|
+
|
149
|
+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
```
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
```Swift4
|
164
|
+
|
165
|
+
OneViewController.swift
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
import UIKit
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
class OneViewController: UIViewController
|
174
|
+
|
175
|
+
{
|
176
|
+
|
177
|
+
init()
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
super.init(nibName: nil, bundle: nil)
|
182
|
+
|
183
|
+
//背景色の設定
|
184
|
+
|
185
|
+
self.view.backgroundColor = UIColor.blue
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
//システムアイコンの設定
|
190
|
+
|
191
|
+
let systemIcon = UITabBarItem(tabBarSystemItem: .bookmarks , tag: 1)
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
//タブのアイコンの設定
|
196
|
+
|
197
|
+
self.tabBarItem = systemIcon
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
required init?(coder aDecoder: NSCoder)
|
204
|
+
|
205
|
+
{
|
206
|
+
|
207
|
+
super.init(coder: aDecoder)
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
override func viewDidLoad() {
|
216
|
+
|
217
|
+
super.viewDidLoad()
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
// Do any additional setup after loading the view.
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
override func didReceiveMemoryWarning() {
|
228
|
+
|
229
|
+
super.didReceiveMemoryWarning()
|
230
|
+
|
231
|
+
// Dispose of any resources that can be recreated.
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
/*
|
240
|
+
|
241
|
+
// MARK: - Navigation
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
246
|
+
|
247
|
+
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
248
|
+
|
249
|
+
// Get the new view controller using segue.destinationViewController.
|
250
|
+
|
251
|
+
// Pass the selected object to the new view controller.
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
*/
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
```
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
```Swift4
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
import UIKit
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
class TwoViewController: UIViewController
|
276
|
+
|
277
|
+
{
|
278
|
+
|
279
|
+
init()
|
280
|
+
|
281
|
+
{
|
282
|
+
|
283
|
+
super.init(nibName: nil, bundle: nil)
|
284
|
+
|
285
|
+
//背景色の設定
|
286
|
+
|
287
|
+
self.view.backgroundColor = UIColor.white
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
//システムアイコンの設定
|
292
|
+
|
293
|
+
let systemIcon = UITabBarItem(tabBarSystemItem: .favorites, tag: 2)
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
//タブのアイコンの設定
|
300
|
+
|
301
|
+
self.tabBarItem = systemIcon
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
required init?(coder aDecoder: NSCoder)
|
308
|
+
|
309
|
+
{
|
310
|
+
|
311
|
+
super.init(coder: aDecoder)
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
override func viewDidLoad() {
|
320
|
+
|
321
|
+
super.viewDidLoad()
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
// Do any additional setup after loading the view.
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
override func didReceiveMemoryWarning() {
|
332
|
+
|
333
|
+
super.didReceiveMemoryWarning()
|
334
|
+
|
335
|
+
// Dispose of any resources that can be recreated.
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
/*
|
344
|
+
|
345
|
+
// MARK: - Navigation
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
350
|
+
|
351
|
+
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
352
|
+
|
353
|
+
// Get the new view controller using segue.destinationViewController.
|
354
|
+
|
355
|
+
// Pass the selected object to the new view controller.
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
*/
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
```
|