以下のコードで簡単な検証をしてみましたが、ボタンはタップ可能でした。
UIScrollView
- UIView
- UIButton
の階層です
ご自身が書いたコードとくらべてみてください。
ボタンのサイズがちゃんと設定されているか、Button
の上に何か別のView
が乗っていないかなど。
swift
1import UIKit
2
3class ViewController: UIViewController {
4
5 var scrollView = UIScrollView()
6 var coverView = UIView()
7 var button = UIButton()
8
9 override func viewDidLoad() {
10 super.viewDidLoad()
11
12 button.frame = CGRect(x: 200, y: 200, width: 200, height: 100)
13 button.backgroundColor = UIColor.blue
14 button.addTarget(self, action: #selector(self.pushButton), for: .touchUpInside)
15 coverView.addSubview(button)
16
17 coverView.frame = CGRect(x: 0, y: 0, width: 375 * 3, height: 667 * 3)
18 coverView.backgroundColor = UIColor.orange
19 scrollView.addSubview(coverView)
20
21 scrollView.frame = CGRect(x: 0, y: 0, width: 375, height: 667)
22 scrollView.contentSize = coverView.bounds.size
23 scrollView.backgroundColor = UIColor.yellow
24 view.addSubview(scrollView)
25 }
26
27 func pushButton() {
28 print("Push!")
29 }
30}