簡體   English   中英

Uiview動畫不起作用

[英]Uiview animation doesn't work

所以這是我的代碼:

- (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]]];
}

標頭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];
}

每當用戶將新記錄添加到tableview時,我都會調用updateTotalLabel。 我對動畫有問題,因為動畫只能在首次調用updateLabel之后才能工作。

編輯

好吧,所以我看電影: YT

在輸出中,您可以看到何時觸發每個動畫。

不太確定您的問題是什么,因為實際上沒有描述正在發生的事情和未發生的事情。 我確實看到了您的動畫代碼有問題。 您正在嘗試使用延遲來允許多個連續動畫。 這可能有用,我真的不知道。 但是,更好的方法是僅使用完成塊來繼續您想要的動畫。 嘗試這個:

-(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 1!");
                         frame.origin.y = 0;
                         self.label.text = string;
                         [UIView animateWithDuration:0.5
                                               delay:0.0
                                             options: UIViewAnimationTransitionCurlDown
                                          animations:^{
                                              self.frame = frame;
                                          } 
                                          completion:^(BOOL finished){
                                              NSLog(@"Done 2!");
                                              [label setNeedsDisplay];
                                          }];
                     }];



}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM