2013-11-07 3 views
-2

Я бы сделал символ набора анимации NSString с помощью символа, как пишущая машинка. Строка будет помещена в UILabel. Возможно? Если да, то как?Создайте строчную анимацию, такую ​​как пишущая машинка

Заранее спасибо.

UPDATE

метод Возняк работает хорошо, но я не могу использовать его для решения моей проблемы. Я попытаюсь объяснить свою ситуацию. В мое приложение на первый взгляд, я бы показать реальное положение, так что я добавил следующие методы:

- (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) на - (NSString *)sanitizedDescription:(NSString *)obj называется. Как я могу сделать?

Извините, но я в начале с Obj-C :(

+3

Вы что-нибудь пробовали? – woz

ответ

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

} 
Смежные вопросы