-2

タイプライターのように 1 文字ずつ入力する NSString アニメーションを作成します。文字列は UILabel に配置されます。可能です?はいの場合、どのように?

前もって感謝します。

アップデート

woz の方法はうまく機能しますが、問題の解決には使用できません。私は自分の状況を説明しようとします。最初のビューの私のアプリでは、実際の位置を表示するので、これらのメソッドを追加しました:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    //NSLog(@"didUpdateToLocation: %@", newLocation);
    CLLocation *currentLocation = newLocation;

    if (currentLocation != nil) {
        longitude.text = [NSString stringWithFormat:@"%.3f", currentLocation.coordinate.longitude];
        latitude.text = [NSString stringWithFormat:@"%.3f", currentLocation.coordinate.latitude];
    }

    NSLog(@"Resolving the Address");
    [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        //NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
        if (error == nil && [placemarks count] > 0) {
            placemark = [placemarks lastObject];
            [address sizeToFit];

            address.text = [NSString stringWithFormat:@"%@, %@\n%@ %@\n%@",
                            [self sanitizedDescription:placemark.thoroughfare],
                            [self sanitizedDescription:placemark.subThoroughfare],
                            [self sanitizedDescription:placemark.postalCode],
                            [self sanitizedDescription:placemark.locality],
                            [self sanitizedDescription:placemark.country]];
        } else {
            NSLog(@"%@", error.debugDescription);
        }
    } ];

}

- (NSString *)sanitizedDescription:(NSString *)obj
{
    if (obj == nil)
    {
        obj = @"...";
        return obj;
    }
    return obj;
}

if (obj == nil)on- (NSString *)sanitizedDescription:(NSString *)objが呼び出されたときに、タイプライター アニメーションを使用します。どのようにできるのか?

申し訳ありませんが、私は Obj-C から始めています :(

4

1 に答える 1

2

これは、開始するためのコードです。NSTimer を使用して、定期的に UILabel に文字を追加しています。

- (void)viewDidLoad {

    NSTimer *typingTimer = [NSTimer scheduledTimerWithTimeInterval:0.2
        target:self
        selector:@selector(typeALetter:)
        userInfo:nil
        repeats:YES];

    NSString *stringToType = @"The quick brown fox jumps over the lazy dog.";
    NSUInteger index = 0;
}

- (void)typeALetter:(id)sender {

    theLabel.text = [theLabel.text stringByAppendingFormat:@"%@", [stringToType substringWithRange:NSMakeRange(index, 1)]];

    if (index < stringToType.length) {
        index++;
    }
    else {
        [typingTimer invalidate];
    }    

}
于 2013-11-07T20:14:19.140 に答える