使用 CGFloat 变量调用 func

Calling func with CGFloat variable

我试图用下面的代码调用一个带有 CGFloat 变量的函数,但它没有到达我想要的位置。我可以知道它有什么问题吗?

var triggerTime = (Int64(NSEC_PER_SEC) * 10)
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, triggerTime), dispatch_get_main_queue(), { () -> Void in
        self.AnswerUp(1500)


func AnswerUp (upValue: CGFloat){
    Answer1.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
    Answer2.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
    Answer3.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
    Answer4.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left



    self.AnswerView.frame = CGRectMake(self.AnswerView.frame.origin.x , self.AnswerView.frame.origin.y + 300, self.AnswerView.frame.size.width, self.AnswerView.frame.size.height)

    AnswerView.alpha=1.0
    UIView.animateWithDuration(1.0, animations:{
        self.AnswerView.frame = CGRectMake(self.AnswerView.frame.origin.x , self.AnswerView.frame.origin.y - upValue, self.AnswerView.frame.size.width, self.AnswerView.frame.size.height)
    })


}

CGFloat 值太高 1500。我认为你的 Y 位置计算 self.AnswerView.frame.origin.y - upValue 导致负值使对象离开屏幕。打印 self.AnswerView.frame 并检查值!