foh*_*oho 3 animation objective-c ios
我正在使用NSTimer(5秒持续时间)和选择器从NSArray中随机选择名称.
这是一些代码
....
NSDate *endtime = [NSDate dateWithTimeIntervalSinceNow:5];
[NSTimer scheduledTimerWithTimeInterval:0.2
target:self
selector:@selector(selectPlayer:)
userInfo:endtime
repeats:YES ];
Run Code Online (Sandbox Code Playgroud)
...
-(void)selectPlayer:(NSTimer *)timer
{
if ([timer.userInfo timeIntervalSinceNow] < 0)
{
[timer invalidate];
}
NSString *playerName = [[NSString alloc]initWithFormat:@"%@",
[self.playersNames objectAtIndex:random() & [self.playersNames count]-1]];
self.playersLabel.text = playerName;
[playerName release];
}
Run Code Online (Sandbox Code Playgroud)
该代码完美地运作.self.playersLabel每隔0.2秒填充一个随机名称.
我想要的是添加一些fadein/fadeout动画效果,同时在playersLabel中更改名称.
怎么实现呢?
您可以使用它来设置文本:
[UIView animateWithDuration:0.4 animations:^{
self.playersLabel.alpha = 0;
} completion:^(BOOL finished) {
self.playersLabel.text = @"Other text";
[UIView animateWithDuration:0.4 animations:^{
self.playersLabel.alpha = 1;
}];
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1883 次 |
| 最近记录: |