【问题标题】:UIview dose not respond at calling view controllerUIview 在调用视图控制器时没有响应
【发布时间】:2016-04-17 19:41:39
【问题描述】:

奇怪的事情发生在我身上,我有一个 uiviewcontroller,里面有一个 UIView,它有 2 个视图,以显示图形栏的错觉:

The UIVIEW with bars

现在的事情是我第一次打开视图控制器没有任何反应,栏不会升高,切换到另一个视图然后回来后一切正常,栏会升高。 现在这里是关键,ViewDidLoad 和 ViewWillApper 使用相同的函数并通过断点和 println 所有数据到达 uiviewAnimation 以使条形上升,但没有任何反应,除非重新加载视图

发生了什么事?请照亮我

 override func viewDidLoad() {
    super.viewDidLoad()


    TimeNow()

    InsertNetoToCircul()
    InsertSpendIntoCircul()
    Checking()
    AdvicesFunction()


}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    InsertNetoToCircul()
    InsertSpendIntoCircul()
    Checking()
    AdvicesFunction()


}


    func SpendBar(high : CGFloat,income:Float){

    if high < 1{
        OtzaotLabel.hidden = true
    }
    else{
        OtzaotLabel.hidden = false
    }
    if income < 1{
        LoLabel.hidden = true
    }
    else{
        LoLabel.hidden = false
    }


    SpendBarView.frame.origin.x = 38
    SpendBarView.frame.origin.y = 335

    SpendBarView.frame.size.width = 70

    // Calculate location in bar
    //Spendings
    var Mana:Int = (Int(high) / 500) * 30
    var Sher:Float! = ((Float(high) % 500) / 500 ) * 30

    if Rate{ Mana /= 2 }


    UIView.animateWithDuration(0.4, animations: {

        self.SpendBarView.frame.size.height = -CGFloat(Float(Mana) + Sher)

    })

    SpendBarView.backgroundColor = UIColor(red: 1.0, green: 0.4, blue: 0.4, alpha: 1)}

【问题讨论】:

    标签: ios iphone swift uiview


    【解决方案1】:

    您不能在viewDidLoad 中制作动画,因为该视图尚未在界面中。视图已加载;这意味着视图控制器一个视图。但尚未添加到界面中。在添加界面之前,您不能在视图上执行动画;您甚至无法在将视图添加到界面时在同一运行循环中对视图执行动画。在您尝试对其进行动画处理之前,该视图必须已经在界面中,并在那里完全建立。

    【讨论】:

    • 回答得很好,谢谢,但是通过它有什么建议吗?
    • 移到viewDidAppear
    • 我通过使用 viewdidapper() 解决了这个问题,谢谢你的时间伙伴 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-11
    • 1970-01-01
    • 2019-06-11
    相关资源
    最近更新 更多