gpt4 book ai didi

ios - 自定义 View - uiview 的子类不能调整大小

转载 作者:行者123 更新时间:2023-11-28 15:57:10 27 4
gpt4 key购买 nike

这一定是一件简单的事情,但我找不到线索,

我有一个 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com