質問編集履歴
5
マルチポストの説明
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,6 +8,11 @@
|
|
8
8
|

|
9
9
|
|
10
10
|
※各ControllerのUIはxibで作成しており、GraphViewControllerは横画面です。
|
11
|
+
|
12
|
+
### マルチポストの理由
|
13
|
+
terarailのヘルプを確認していませんでした。
|
14
|
+
今後はマルチポストを行わないようにします。
|
15
|
+
https://ja.stackoverflow.com/questions/95115/swift-%e7%94%bb%e9%9d%a2%e9%81%b7%e7%a7%bb%e6%99%82%e3%81%ab%e7%94%bb%e9%9d%a2%e3%82%92%e5%9b%9e%e8%bb%a2%e3%81%95%e3%81%9b%e3%81%a6%e8%a1%a8%e7%a4%ba%e3%81%97%e3%81%9f%e3%81%84
|
11
16
|
|
12
17
|
### 発生している問題
|
13
18
|
ビルドして最初にTopViewControllerからGraphViewControllerに遷移したときは問題なく画面が回転され横画面で表示されますが、その後TopViewControllerに戻ったときに縦画面への回転がされず横画面のままで表示されています。
|
4
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
### 実現したいこと
|
2
2
|
画面遷移したときに、それぞれの画面に対応した向きに回転させて表示したい。
|
3
3
|
### 前提
|
4
|
-
|
4
|
+
iosアプリ開発の初心者です。縦画面と横画面の複数の画面からなるアプリを開発中ですが、下記の問題を自力で解決することができなかったので、どうすればよいのかご教授をお願いしたいです。
|
5
5
|
|
6
6
|
TabBarControllerを使用しており、各画面をTabを使い画面遷移します。それぞれ専用のPageViewControllerで管理しているGraphViewController(横画面)とTopViewController(縦画面)で遷移するときに、それぞれの画面に対応した向きに回転させて表示したいのですが、下記の問題が起きています。
|
7
7
|
|
3
状況の更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
### 前提
|
4
4
|
IOSアプリ開発の初心者です。縦画面と横画面の複数の画面からなるアプリを開発中ですが、下記の問題を自力で解決することができなかったので、どうすればよいのかご教授をお願いしたいです。
|
5
5
|
|
6
|
-
TabBarControllerを使用しており、各画面をTabを使い画面遷移します。
|
6
|
+
TabBarControllerを使用しており、各画面をTabを使い画面遷移します。それぞれ専用のPageViewControllerで管理しているGraphViewController(横画面)とTopViewController(縦画面)で遷移するときに、それぞれの画面に対応した向きに回転させて表示したいのですが、下記の問題が起きています。
|
7
7
|
|
8
|
-

|
9
9
|
|
10
10
|
※各ControllerのUIはxibで作成しており、GraphViewControllerは横画面です。
|
11
11
|
|
@@ -13,88 +13,80 @@
|
|
13
13
|
ビルドして最初にTopViewControllerからGraphViewControllerに遷移したときは問題なく画面が回転され横画面で表示されますが、その後TopViewControllerに戻ったときに縦画面への回転がされず横画面のままで表示されています。
|
14
14
|
|
15
15
|
### 該当のソースコード
|
16
|
-
```T
|
16
|
+
```TabBarController
|
17
|
-
class T
|
17
|
+
class TabBarController: UITabBarController {
|
18
|
-
private var controllers: [UIViewController] = []
|
19
|
-
|
20
|
-
|
18
|
+
override func viewDidLoad() {
|
21
19
|
super.viewDidLoad()
|
22
|
-
|
23
|
-
self.initTopPageViewContoller()
|
24
|
-
|
25
|
-
// Do any additional setup after loading the view.
|
26
20
|
}
|
27
|
-
|
28
|
-
private func initTopPageViewContoller() {
|
29
|
-
let topVC = storyboard!.instantiateViewController(withIdentifier: "TopView") as! TopViewController
|
30
|
-
|
31
|
-
self.controllers = [topVC]
|
32
|
-
|
33
|
-
setViewControllers([self.controllers[0]], direction: .forward, animated: true, completion: nil)
|
34
|
-
|
35
|
-
self.dataSource = self
|
36
|
-
}
|
37
21
|
}
|
38
22
|
|
39
|
-
extension T
|
23
|
+
extension UITabBarController {
|
24
|
+
open override var shouldAutorotate: Bool {
|
40
|
-
f
|
25
|
+
if let VC = selectedViewController {
|
41
|
-
return s
|
26
|
+
return VC.shouldAutorotate
|
27
|
+
}else{
|
28
|
+
return true
|
29
|
+
}
|
42
30
|
}
|
43
31
|
|
44
|
-
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
|
45
|
-
return nil
|
46
|
-
}
|
47
|
-
|
48
|
-
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
|
49
|
-
return nil
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
//TopViewControllerの回転制御
|
54
|
-
extension TopPageViewController {
|
55
|
-
open override var shouldAutorotate: Bool{
|
56
|
-
guard let topVC = self.controllers.first
|
57
|
-
else {
|
58
|
-
return false
|
59
|
-
}
|
60
|
-
return topVC.shouldAutorotate
|
61
|
-
}
|
62
|
-
|
63
|
-
override
|
32
|
+
open override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
64
|
-
|
33
|
+
if let VC = selectedViewController {
|
34
|
+
return VC.supportedInterfaceOrientations
|
65
|
-
else
|
35
|
+
}else{
|
66
36
|
return .portrait
|
67
37
|
}
|
68
|
-
return topVC.supportedInterfaceOrientations
|
69
38
|
}
|
70
39
|
}
|
71
40
|
```
|
41
|
+
```TopPageViewController
|
42
|
+
class TopPageViewController: UIPageViewController {
|
43
|
+
override var shouldAutorotate: Bool {
|
44
|
+
if let VC = controllers.first {
|
45
|
+
return VC.shouldAutorotate
|
46
|
+
}
|
47
|
+
return false
|
48
|
+
}
|
49
|
+
|
50
|
+
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
51
|
+
if let VC = controllers.first {
|
52
|
+
return VC.supportedInterfaceOrientations
|
53
|
+
}
|
54
|
+
return .portrait
|
55
|
+
}
|
56
|
+
```
|
72
57
|
```TopViewController
|
73
58
|
class TopViewController: UIViewController {
|
74
|
-
var topView = TopView()
|
75
|
-
|
76
59
|
override var shouldAutorotate: Bool {
|
77
60
|
UIDevice.current.setValue(1, forKey: "orientation")
|
78
61
|
return false
|
79
62
|
}
|
80
63
|
|
81
64
|
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
82
|
-
return .portrait
|
65
|
+
return .portrait
|
83
66
|
}
|
84
|
-
|
67
|
+
```
|
68
|
+
```GraphPageViewController
|
69
|
+
lass GraphPageViewController: UIPageViewController {
|
85
|
-
override
|
70
|
+
override var shouldAutorotate: Bool {
|
86
|
-
super.viewDidLoad()
|
87
|
-
|
88
|
-
UIDevice.current.setValue(1, forKey: "orientation")
|
89
|
-
|
71
|
+
if let VC = controllers.first {
|
90
|
-
|
72
|
+
return VC.shouldAutorotate
|
73
|
+
}else{
|
74
|
+
return true
|
91
75
|
}
|
76
|
+
}
|
77
|
+
|
78
|
+
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
79
|
+
if let VC = controllers.first {
|
80
|
+
return VC.supportedInterfaceOrientations
|
81
|
+
}else{
|
82
|
+
return .landscapeLeft
|
83
|
+
}
|
84
|
+
}
|
92
85
|
```
|
93
86
|
```GraphViewController
|
94
87
|
class GraphViewController: UIViewController {
|
95
|
-
var
|
88
|
+
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
96
89
|
|
97
|
-
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
98
90
|
if(UIDevice.current.orientation.rawValue == 4){
|
99
91
|
UIDevice.current.setValue(4, forKey: "orientation")
|
100
92
|
return .landscapeLeft
|
@@ -104,6 +96,7 @@
|
|
104
96
|
return .landscapeRight
|
105
97
|
}
|
106
98
|
}
|
99
|
+
|
107
100
|
override var shouldAutorotate: Bool {
|
108
101
|
if(UIDevice.current.orientation.rawValue == 1){
|
109
102
|
return false
|
@@ -113,15 +106,12 @@
|
|
113
106
|
}
|
114
107
|
}
|
115
108
|
|
116
|
-
|
109
|
+
override func viewDidLoad() {
|
117
|
-
|
110
|
+
super.viewDidLoad()
|
118
|
-
|
119
|
-
UIDevice.current.setValue(4, forKey: "orientation")
|
120
|
-
print(supportedInterfaceOrientations)
|
121
111
|
|
122
|
-
|
112
|
+
UIDevice.current.setValue(4, forKey: "orientation")
|
113
|
+
print(supportedInterfaceOrientations)
|
123
|
-
|
114
|
+
}
|
124
|
-
|
125
115
|
```
|
126
116
|
### 試したこと
|
127
117
|
|
@@ -133,3 +123,6 @@
|
|
133
123
|
【Swift】一画面だけ横向き固定にする
|
134
124
|
https://freelance-style.net/%E3%80%90swift%E3%80%91%E4%B8%80%E7%94%BB%E9%9D%A2%E3%81%A0%E3%81%91%E6%A8%AA%E5%90%91%E3%81%8D%E5%9B%BA%E5%AE%9A%E3%81%AB%E3%81%99%E3%82%8B/
|
135
125
|
|
126
|
+
【Swift4】特定の画面で回転を制御する方法について、サンプルを作って理解する
|
127
|
+
https://qiita.com/orimomo/items/6ab57c6706a8dbc181a1
|
128
|
+
|
2
説明の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
### 実現したいこと
|
2
2
|
画面遷移したときに、それぞれの画面に対応した向きに回転させて表示したい。
|
3
3
|
### 前提
|
4
|
-
IOSアプリ開発の初心者です。縦画面と横画面の複数の画面からなるアプリを開発中ですが、
|
4
|
+
IOSアプリ開発の初心者です。縦画面と横画面の複数の画面からなるアプリを開発中ですが、下記の問題を自力で解決することができなかったので、どうすればよいのかご教授をお願いしたいです。
|
5
5
|
|
6
6
|
TabBarControllerを使用しており、各画面をTabを使い画面遷移します。GraphViewController(横画面)とPageViewControllerを使用して表示しているTopViewController(縦画面)で遷移するときに、それぞれの画面に対応した向きに回転させて表示したいのですが、下記の問題が起きています。
|
7
7
|
|
1
誤字の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -69,7 +69,7 @@
|
|
69
69
|
}
|
70
70
|
}
|
71
71
|
```
|
72
|
-
```TopViewContoller
|
72
|
+
```TopViewController
|
73
73
|
class TopViewController: UIViewController {
|
74
74
|
var topView = TopView()
|
75
75
|
|
@@ -90,7 +90,7 @@
|
|
90
90
|
|
91
91
|
}
|
92
92
|
```
|
93
|
-
```GraphViewontroller
|
93
|
+
```GraphViewController
|
94
94
|
class GraphViewController: UIViewController {
|
95
95
|
var graphView = GraphView()
|
96
96
|
|