【问题标题】:Having trouble keep KDCircularProgress view inside parent view无法将 KDCircularProgress 视图保留在父视图中
【发布时间】:2018-04-01 08:39:00
【问题描述】:

我尝试在我的项目中使用 KDCircularProgress in progressView 类,它固有的 UIView 类

init(frame: CGRect) {

    progress = KDCircularProgress(frame: frame)

    letter = "A"

    super.init(frame: frame)

    setupCircularProgress(frame: frame)

    UILabel()
        .add(to: self)
        .layout { (make) in
            make.center.equalToSuperview()
    }.config { (view) in
        view.text = letter
    }   

}

和 setupCircularProgress 函数:

func setupCircularProgress(frame:CGRect) {
    progress.clockwise = true
    progress.set(colors: randomColor(hue: .random, luminosity: .light))
    progress.glowMode = .forward
    progress.glowAmount = 0
    progress.center = self.center
    progress.trackColor = UIColor.white


    self.addSubview(progress)

    progress.animate(fromAngle: 0, toAngle: 360, duration: 5, completion: { completed in
        if completed {
            print("animation stopped, completed")
            self.removeFromSuperview()
        } else {
            print("animation stopped, was interrupted")
        }
    })
}

在视图控制器中

LetterView(frame: CGRect(x: 50, y: 50, width: 50, height: 50)).add(to: self.playView!)

但它显示如下 showed view

我不知道为什么 KDCircularProgress 在框架之外,只有 textLabel 在正确的位置。 而且 KDCircularProgress 视图不会根据分配的框架出现在哪里。

如果有人处理过这种情况和问题,请告诉我如何解决。

【问题讨论】:

    标签: swift uiview uiviewanimation kdcircularprogress


    【解决方案1】:

    有趣的是,我提出问题后马上得到了答案:)

    在我的自定义 UIView 中,我应该像这样初始化 KDCircularProgress

     progress = KDCircularProgress(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.height))
    

    因为位置是相对于 UIView 的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 1970-01-01
      • 2021-12-27
      相关资源
      最近更新 更多