Uiview动画不起作用
所以这是我的代码:
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 0) {
if (!header) {
header = [[CustomBackground alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
float number = [self.total floatValue];
[self updateTotalLabel: &number];
}
return header;
}
return nil;
}
-(void)updateTotalLabel:(float *)amount
{
float currentValue = [self.total floatValue];
self.total = [NSNumber numberWithFloat:(currentValue + *amount)];
[header updateLabel:[NSString stringWithFormat:TOTAL, [total floatValue]]];
}
header updateLabel:
-(void)updateLabel:(NSString *)string
{
CGRect frame = self.frame;
frame.origin.y = -frame.size.height;
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^{
self.frame = frame;
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
self.frame = frame;
frame.origin.y = 0;
self.label.text = string;
[UIView animateWithDuration:0.5
delay:1.0
options: UIViewAnimationTransitionCurlDown
animations:^{
self.frame = frame;
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
[label setNeedsDisplay];
}
每次用户向表视图添加新记录时,我都会调用 updateTotalLabel 。 我对动画有疑问,因为动画仅在第一次调用 updateLabel 后才起作用。
编辑
好的,所以我录了一部电影: YT
在输出中,您可以看到每个动画何时播放扳机。
So it is my code:
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 0) {
if (!header) {
header = [[CustomBackground alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
float number = [self.total floatValue];
[self updateTotalLabel: &number];
}
return header;
}
return nil;
}
-(void)updateTotalLabel:(float *)amount
{
float currentValue = [self.total floatValue];
self.total = [NSNumber numberWithFloat:(currentValue + *amount)];
[header updateLabel:[NSString stringWithFormat:TOTAL, [total floatValue]]];
}
header updateLabel:
-(void)updateLabel:(NSString *)string
{
CGRect frame = self.frame;
frame.origin.y = -frame.size.height;
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^{
self.frame = frame;
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
self.frame = frame;
frame.origin.y = 0;
self.label.text = string;
[UIView animateWithDuration:0.5
delay:1.0
options: UIViewAnimationTransitionCurlDown
animations:^{
self.frame = frame;
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
[label setNeedsDisplay];
}
I am calling updateTotalLabel, every time when user adds new record to tableview.
I have a problem with animation because, animation works only after first call updateLabel.
EDIT
Ok, so I rec a movie: YT
In output you can see when each animation is trigger.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不太确定你的问题是什么,因为实际上没有描述正在发生的事情和没有发生的事情。不过,我确实发现您的动画代码有问题。您正在尝试使用延迟来允许多个连续动画。它可能会起作用,我真的不知道。然而,更好的方法是使用完成块来继续您想要的动画。试试这个:
Not really sure what your problem is, as there is really no description of what is happening and what is not happening. I do see a problem with your animation code though. You're attempting to use delays to allow for multiple continuous animations. It might work, I really don't know. However, a better method is just to use the completion block to continue with what ever animation you want. Try this: