点击我的应用中的图片并且图片位于顶部时,图片将始终完美向下移动。但是当图像位于底部时,图像有时不会向上移动。即使它没有移动,该过程仍然会运行,并且它会记录为好像它位于顶部。我尝试了所有我知道怎么做但你看错了吗?谢谢!
- (void )imageTapped:(UITapGestureRecognizer *) gestureRecognizer
{
NSLog(@"imageTapped");
[UIView beginAnimations:@"move" context:nil];
[UIView setAnimationDuration:0.3];
if (self.imgV.frame.origin.y == 20) {
NSLog(@"Top");
upOrDown = @"1";
self.invalidateTheTimer = @"";
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
self.imgV.frame=CGRectMake(0, self.view.frame.size.height-self.imgV.frame.size.height, self.imgV.frame.size.width, self.imgV.frame.size.height);
self.vBottom.frame=CGRectMake(0, self.imgV.frame.origin.y+self.imgV.frame.size.height, self.vBottom.frame.size.width, self.vBottom.frame.size.height);
} else if (self.imgV.frame.origin.y >= 507) {
NSLog(@"Bottom");
self.imgV.frame=CGRectMake(0, 20, self.imgV.frame.size.width, self.imgV.frame.size.height);
self.vBottom.frame=CGRectMake(0, self.imgV.frame.origin.y+self.imgV.frame.size.height, self.vBottom.frame.size.width, self.vBottom.frame.size.height);
[hour setText:@""];
[minute setText:@""];
[second setText:@""];
[timer invalidate];
self.invalidateTheTimer = @"INVALIDATE";
}
NSLog(@"%f", self.imgV.frame.origin.y);
[UIView commitAnimations];
}
答案 0 :(得分:0)
考虑到你还没有发布你的整个代码,很难弄清楚究竟是什么错,但是看看你做的那些烂摊子,我建议你去看看进入block based animations,这应该简化你想要完成的事情。
此外,如果我不得不猜测,我说这个问题出现在你的计时器中,而且它调用的任何方法都可能搞乱了你的动画。