LoginSignup
0
2

More than 3 years have passed since last update.

scrollviewで可変サイズUIViewがタップできなくてハマった

Last updated at Posted at 2020-11-14

ContainerVCを用いて、
ボタンを押すと大きさが可変となるUIViewを作成していました。
このUIViewにはtapgestureRecognizer あるいは touchesbeganで
タップを検出できるようにしていました。
(参考 https://qiita.com/Kyome/items/d86cefa9dbd7bd2d7cf0)

ボタンが押されたときに

a.swift
@IBOutlet weak var containerVCWidth: NSLayoutConstraint!
  self.myScrollView.contentSize.width += 100
  self.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width + 100, height: self.view.frame.height)
}

としていましたが、viewは大きくなるのにタップできない現象が発生しました。

解決策

containerViewのwidthに関する制約を
outlet接続して、それもインクリメントする必要があったようです。

a.swift
@IBOutlet weak var containerVCWidth: NSLayoutConstraint!

@IBAction func tappedButton(_ sender: Any) {
  self.myScrollView.contentSize.width += 100
  containerVCWidth.constant += 100
}
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2