这一定是一件简单的事情,但我找不到线索,
我有一个 imageview 并尝试一个涂鸦 View ,它是 UIview 的子类,在它上面允许涂鸦。除了调整涂鸦 View 的大小外,一切正常,它一直占据整个屏幕,我无法将其缩小。
class ScribbleView: UIView
{
let backgroundLayer1 = CAShapeLayer()
required init()
{
// super.init(frame: CGRect.zero)
super.init(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
layer.addSublayer(backgroundLayer1)
layer.masksToBounds = true
}
class HermiteScribbleView: ScribbleView, Scribblable
{
required init() {
print ("calling parent")
super.init()
}
}
/** 主要代码**/
let hermiteScribbleView = HermiteScribbleView()
hermiteScribbleView.backgroundColor = .red
// imgView.autoresizesSubviews = true
// hermiteScribbleView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
//once this is done, hermieScribbleView is always stretched to full width and height no matter what I try
imgView.addSubview(hermiteScribbleView)
最佳答案
根据以上信息我猜测,您可能正在使用 UIImageView
的框架来设置 UIView
的框架。您需要将 UIView
的大小设置为与 UIImage
的大小相同。
imgImageView.image.size
然后将 UIView
的中心设置为与 UIImageView
的中心相同。
希望这会奏效。
关于ios - 自定义 View - uiview 的子类不能调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41539642/