简体   繁体   English

通过动画在iPhone中交换文本

[英]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 我想在IOS App中交换文本以指定帮助文本,我的意思是,我需要显示

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

is it possible by using CABasicAnimation? 使用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 所以我需要使文本闪烁60秒,然后每显示10秒

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). 据我所知,文本不是任何对象(UILabel,UITextView等)的可动画化属性,但是有许多控件可以将这些对象作为子类并允许可动画化的文本(除其他属性外)。 For example, AUIAnimateableText . 例如, 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. 要更改用户看到的内容的文本,您需要首先将其连接为iboutlet。 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. 为了获得与实际为文本设置动画效果接近的效果,您可以在其中包含2个UILabel其中包含所需的文本并为其hidden属性设置动画。 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. 您可以做很多事情,只需淡入和淡出,甚至翻转标签或向左/向右滑动等等。如果您想获得打字机效果,则可以在代码中创建适当的UILabel并使它们出现,等等。

As for the timing, just use the easy-to-use and well documented NSTimer . 至于时间,只需使用易于使用且有据可查的NSTimer

try this.,. 尝试这个。,。

here i am changing the label text,.., 在这里,我正在更改标签文本,..,

in viewdidload have one timer.,., 在viewdidload中有一个计时器。

 - (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. 调用此Loadtimer方法。取决于计时周期。 for every 5 seconds LoadTimer method is called and that method change the text for the label,.., 每5秒钟调用一次LoadTimer方法,该方法将更改标签的文本。

i am learning.,., 我在学习。,。,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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