2

ラベルテキストをアニメーション化する必要があります@"text . ", @"text . ", @"text . ", @"text ."

したがって、ユーザーにはドット アニメーションのみが表示されます。ラベル テキストには中央揃えを使用します。

そのためにタイマーを使用します。

- (void)processTimerFired:(NSTimer *)timer {
    NSMutableDictionary *dict = [timer userInfo];
    NSMutableString *string = [[dict objectForKey:@"label"] mutableCopy];
    int dotNumber = [[dict objectForKey:@"dot"] intValue];
    if (dotNumber == 3) {
        dotNumber = 1;
    }
    else {
        dotNumber += 1;
    }

    [dict setObject:@(dotNumber) forKey:@"dot"];

    for (int i = 1; i < 4; i++) {
        if (i == dotNumber) {
            [string appendString:@"."];
        }
        else {
            [string appendString:@" "];
        }
    }

    self.informationLabel.text = string;
}

iOS 6 ではすべて問題ありませんが、iOS 7 では xcode がスペースの数を減らしているように見えるため、テキストの出所が常に異なります。そのため、テキストが揺れているように見えます。

テスト用に最後に「+」をつけてみました。そして、すべてがOKになりました。そのため、その後に他のシンボルがない場合にのみ、xcode は「余分な」スペースを削除するようです。

4

2 に答える 2

0

私はその問題でテストを行っていますが、テキストを右に中央揃えする必要があることがわかりました。それが私のコードです:

self.text = @[@"Text.  ",@"Text . ", @"Text  ."];
[self.shorLabel setTextAlignment:NSTextAlignmentCenter];
[self doAnimation:@0];

そして doAnimation メソッド:

- (void) doAnimation: (NSNumber *)index
{
    int indexInt = ([index intValue] +1)%3;
    [self.shorLabel setText:self.text[indexInt]];
    [self.shorLabel sizeToFit];
    [self.shorLabel setFrame:CGRectMake((self.view.frame.size.width - self.shorLabel.frame.size.width)/2, self.shorLabel.frame.origin.y, self.shorLabel.frame.size.width, self.shorLabel.frame.size.height)];
    [self performSelector:@selector(doAnimation:) withObject:@(indexInt) afterDelay:0.2];
}
于 2013-10-04T09:06:56.263 に答える