简体   繁体   中英

Swapping text in iPhone by Animation

I want to swap a text in a IOS App in order to specify a help text, I mean, I need to display

  for a Xsec - "Touch me"
 and then 
    for Xsec - "double tap".

is it possible by using CABasicAnimation? The text need to be displayed in an blink mode, right after I draw was draw a square. So that I need to blink a text for 60sec and display ever 10sec each one

The CAAnimation will take 60sec
0-10sec - "Touch me"  
11-20sec - "double tap"
21-30sec - "Touch me"
....
51-60sec - "Double Tap"

To my knowledge, text isn't an animateable property for any object (UILabel, UITextView, etc.), but there are a number of controls available that subclass these objects and allow animateable text (among other properties). For example, AUIAnimateableText .

Not sure I understand your question, but I'll take a stab at it.

To change the text for something that the user sees, you need it to be hooked up as an iboutlet first. To change the text, just do something like this:

if ([myTextOutlet.text isEqualToString:@"Touch me"])
{
    myTextOutlet.text = @"double tap";
}
else
{
    myTextOutlet.text = @"Touch me";
}

To achieve something close to actually animating the text, you could have 2 UILabel s with the desired texts in it and animate their hidden property. You could do many things, just fade in and out or even flip the label or swipe left/right etc. If you want the typewriter effect, you could create appropriate UILabel s in code and have them appear etc.

As for the timing, just use the easy-to-use and well documented NSTimer .

try this.,.

here i am changing the label text,..,

in viewdidload have one timer.,.,

 - (void)viewDidLoad
  {
  label =[[UILabel alloc]initWithFrame:CGRectMake(367, 664, 220, 21)];
  [label setText:@"Touch me"];
  [label setBackgroundColor:[UIColor redColor]];
  [label setTextColor:[UIColor blueColor]];
  [self.view addSubview:label];
 timer=[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(loadtimer:) userInfo:nil repeats:YES];
   }

  int k=0;
  -(void)loadtimer:(id)sender
   {
   label.text=(k%2) ? @"Touch me" : @"double tap";
   [label setTextColor:( k% 2) ?[UIColor blueColor ]:[UIColor redColor]];
   [label setBackgroundColor:( k% 2) ?[UIColor redColor ]:[UIColor blueColor]];
   CATransition *transition1 = [CATransition animation];
   transition1.duration = 1.0f;
   transition1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
   transition1.type = kCATransitionFade;
   [label.layer addAnimation:transition1 forKey:nil];
   k++;
  }

call this Loadtimer method., depends upon the timing period. for every 5 seconds LoadTimer method is called and that method change the text for the label,..,

i am learning.,.,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM