我试图使用下面的代码调用带有CGFloat变量的func,但它没有进入我想要的位置。我可以知道它有什么问题吗?
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)
})
}
答案 0 :(得分:1)
CGFloat
值过高1500
。我认为您的Y位置计算self.AnswerView.frame.origin.y - upValue
导致负值使对象离开屏幕。打印self.AnswerView.frame
并检查值!