在 iOS中实现喷枪打字动画的代码

2015-10-30 0 598

实现原理比较简单,这里不做过多介绍.

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (copy , nonatomic)NSString *contentStr;

@end

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(animationLabel) object:nil];
    [thread start];
    self.contentStr = @"人生最宝贵的是生命,生命属于人只有一次。一个人的生命应当这样度过:当他回忆往事的时候,他不致因虚度年华而悔恨,也不致因碌碌无为而羞愧;在临死的时候,他能够说:“我的整个生命和全部精力,都已献给世界上最壮丽的事业——为人类的解放而斗争。”";

    
}

- (void)animationLabel
{
    for (NSInteger i = 0; i < self.contentStr.length; i++)
    {
        [self performSelectorOnMainThread:@selector(refreshUIWithContentStr:) withObject:[self.contentStr substringWithRange:NSMakeRange(0, i+1)] waitUntilDone:YES];
        [NSThread sleepForTimeInterval:0.3];
    }
}

- (void)refreshUIWithContentStr:(NSString *)contentStr
{
    self.titleLabel.text = contentStr;
}

最终效果:

在 iOS中实现喷枪打字动画的代码

来自:http://blog.csdn.net/qq_31810357/article/details/49486509

遇见资源网 objective-c 在 iOS中实现喷枪打字动画的代码 http://www.ox520.com/18103.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务