Reputation: 1943
I am trying to call a func with a CGFloat variable with the code below, but it does not go to the position I want. May I know what's the problem with it?
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)
})
}
Upvotes: 0
Views: 42
Reputation: 38162
CGFloat
value is too high 1500
. I think your Y position calculation self.AnswerView.frame.origin.y - upValue
is resulting into negative value making object going out of screen. Print self.AnswerView.frame
and check the value!
Upvotes: 1