回答編集履歴
4
修正
test
CHANGED
@@ -5,3 +5,105 @@
|
|
5
5
|
それでしたら以下が参考になるかもしれません。
|
6
6
|
|
7
7
|
[ swift Button タップ スワイプ](https://teratail.com/questions/31296)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
推測ですが、コードを書いてみました。
|
14
|
+
|
15
|
+
ボタンをサブクラス化してそれをTravelSelectionというUIViewControllerに乗せました。
|
16
|
+
|
17
|
+
タップでボタンの座標が表示されます。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
```swift
|
22
|
+
|
23
|
+
import UIKit
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
class TravelSelection: UIViewController {
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
let button = CustomButton(type: .Custom)
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
override func viewDidLoad() {
|
36
|
+
|
37
|
+
super.viewDidLoad()
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
// ボタンを生成
|
42
|
+
|
43
|
+
button.frame = CGRectMake(100, 100, 200, 100)
|
44
|
+
|
45
|
+
button.setTitle("Button", forState: .Normal)
|
46
|
+
|
47
|
+
button.setTitleColor(UIColor.blueColor(), forState: .Normal)
|
48
|
+
|
49
|
+
button.backgroundColor = UIColor.yellowColor()
|
50
|
+
|
51
|
+
button.addTarget(self, action: #selector(TravelSelection.buttonPressed(_:)), forControlEvents: .TouchUpInside)
|
52
|
+
|
53
|
+
button.userInteractionEnabled = true
|
54
|
+
|
55
|
+
view.addSubview(button)
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
// ボタン押下時の処理
|
62
|
+
|
63
|
+
func buttonPressed(sender: UIButton) {
|
64
|
+
|
65
|
+
print("Button Pressed!")
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
|
72
|
+
|
73
|
+
for touch: AnyObject in touches {
|
74
|
+
|
75
|
+
// 座標取得
|
76
|
+
|
77
|
+
let point = touch.locationInView(self.view)
|
78
|
+
|
79
|
+
print(point)
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
// CustomButton Class
|
92
|
+
|
93
|
+
class CustomButton: UIButton {
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
|
98
|
+
|
99
|
+
super.touchesBegan(touches, withEvent: event)
|
100
|
+
|
101
|
+
self.superview!.touchesBegan(touches, withEvent: event)
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
```
|
3
修正
test
CHANGED
@@ -2,6 +2,6 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
それでしたら以下が参考になるかもしれません。
|
6
|
+
|
5
7
|
[ swift Button タップ スワイプ](https://teratail.com/questions/31296)
|
6
|
-
|
7
|
-
が参考になるかもしれません。
|
2
修正
test
CHANGED
@@ -1,23 +1,7 @@
|
|
1
|
-
TravelSelectionのところを「self」に変えてみてください。
|
2
|
-
|
3
|
-
|
4
|
-
|
5
1
|
そもそものやりたいことですがボタンの位置をボタンが配置してあるUIViewControllerで取得したいということですか?
|
6
2
|
|
7
3
|
|
8
4
|
|
9
|
-
|
5
|
+
[ swift Button タップ スワイプ](https://teratail.com/questions/31296)
|
10
6
|
|
11
|
-
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
|
12
|
-
|
13
|
-
for touch: AnyObject in touches {
|
14
|
-
|
15
|
-
let point = touch.locationInView(self.view)
|
16
|
-
|
17
|
-
|
7
|
+
が参考になるかもしれません。
|
18
|
-
|
19
|
-
}
|
20
|
-
|
21
|
-
}
|
22
|
-
|
23
|
-
```
|
1
修正
test
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
TravelSelectionのところを「self」に変えてみてください。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
そもそものやりたいことですがボタンの位置をボタンが配置してあるUIViewControllerで取得したいということですか?
|
2
6
|
|
3
7
|
|
4
8
|
|