[英]How to animate UILabel?
我正在使用UILabel顯示一些動態文本。 有時會超過標簽寬度。 如果UILabel越界,我想滑動文本。
如何使用UILabel做滑動動畫? 有幫助嗎?
修改我的答案以解決短暫的問題 -
UILabel *label; //Previously initialized UILabel
float newX = 0.0;
float newY = 101.0f;
label.center = CGPointMake(newX, newY);
如果你想為動畫制作動畫,那么添加一個動畫塊是件好事:
UILabel *label; //Previously initialized UILabel
float newX = 90.0f;
float newY = 101.0f;
[UIView transitionWithView:label
duration:0.5f
options:UIViewAnimationCurveEaseInOut
animations:^(void) {
label.center = CGPointMake(newX, newY);
}
completion:^(BOOL finished) {
// Do nothing
}];
請注意,我們只在您希望標簽滑動時為X坐標設置動畫。
-(void)repeat{
[NSTimer scheduledTimerWithTimeInterval:8.0
target:self
selector:@selector(LabelAnimation)
userInfo:nil
repeats:YES];
}
-(void)LabelAnimation
{
NSArray *elements = [yourText componentsSeparatedByString:@","];
NSMutableArray *outputElements = [[NSMutableArray alloc] init];
for (int i=1;i<[elements count];i++)
[outputElements addObject:[elements objectAtIndex:i]];
NSString *outputString = [outputElements componentsJoinedByString:@","];
[UIView animateWithDuration:3.0f delay:0.2f options:UIViewAnimationOptionTransitionNone animations:^{
_header.labelHeaderName.text=outputString;
} completion:^(BOOL finished)
{
if (outputString.length == 0) {
_header.labelHeaderName.text=_strAddress(your saved address);
}
}];
}
當我不得不做類似的事情時,我做到了這一點。 請注意,我正在調整Alpha,而不是位置,但希望這對您有所幫助:
[UIView animateWithDuration:0.3f animations:^{yourLabel.alpha = 0.f;}];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.