现在,这是一个奇怪的问题。一个部门的结果与objective-c和我的手动解决方案不同。很明显,我首先认为我的解决方案是错误的,但是我错过了一些东西或者......不是。Objective-c分区与手动计算不匹配
下面的代码:
GLfloat t = (gone - delay)/kHyAuthenticationViewControllerAnimationDuration;
NSLog(@"%f %f %f", (gone - delay), kHyAuthenticationViewControllerAnimationDuration, t);
这将记录0.017853 3.500000 3.035706
。这意味着0.017853/3.500000
应该是3.035706
,对吗?错误。它实际上是0.00510085714286
。数量不是那么小,会给出精确度问题,即使如此,它可能会轮到像0.0的东西......我是否错过了一些东西?
编辑与全码:
- (void)animateIn:(NSTimer*)timer
{
NSArray *buttons = @[self.registrationButton];//, self.facebookButton, self.linkedInButton, self.twitterButton];
NSDate *when = [timer userInfo];
NSTimeInterval gone = [[NSDate date] timeIntervalSinceDate:when];
NSUInteger finished = 0;
for (int it=0 ; it < [buttons count] ; ++it) {
UIButton *button = [buttons objectAtIndex:it];
GLfloat toValue = self.registrationView.frame.origin.y + 37 + button.frame.size.height * it + 10 * it;
GLfloat fromValue = toValue + self.view.frame.size.height;
GLfloat delay = kHyAuthenticationViewControllerAnimateInDelayFactor * it;
CGRect frame;
// Have we waited enough for this button?
if (gone >= delay) {
// Use the timing function
GLfloat t = (gone - delay)/kHyAuthenticationViewControllerAnimationDuration;
NSLog(@"%f %f %f", (gone - delay), kHyAuthenticationViewControllerAnimationDuration, t);
// t = [HyEasing easeOutBounce:t];
// Is the animation finished for this button?
if (t >= 1.0f) {
t = 1.0f;
++finished;
continue;
}
// Compute current displacement
GLfloat displacement = fabs(toValue - fromValue);
GLfloat y = toValue + displacement * (1.0f - t);
// Create the frame for the animation
frame = CGRectMake(button.frame.origin.x, y, button.frame.size.width, button.frame.size.height);
}
// Make sure the button is at its initial position
else frame = CGRectMake(button.frame.origin.x, fromValue, button.frame.size.width, button.frame.size.height);
[button setFrame:frame];
}
if (finished == [buttons count]) {
[timer invalidate];
}
}
我猜有什么东西你不告诉我们。 (例如,这两条语句之间是否有时间?) – 2014-08-31 02:55:33
显示'kHyAuthenticationViewControllerAnimationDuration'的定义。它是否是一个预处理器宏,其中没有用圆括号括起来的复合表达式? – 2014-08-31 03:15:49
该死的 - .-;你是对的!它被定义为'0.5f + 3'(没有括号)。我怎么能忘记这一点。谢谢。 – 2014-08-31 03:17:39