Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何制作秘密iOS应用程序文本动画_Ios_Uiviewanimation_Textlabel_App Secret - Fatal编程技术网

如何制作秘密iOS应用程序文本动画

如何制作秘密iOS应用程序文本动画,ios,uiviewanimation,textlabel,app-secret,Ios,Uiviewanimation,Textlabel,App Secret,我正在尝试复制机密应用程序的文本标签转换。有人知道最好的方法吗 看起来他们让每个字母以明文颜色开始,然后将其动画化为灰色,然后是白色文本颜色 以下是一些屏幕截图: 这里有一个可能的方法 首先,让我们注意到UILabel可以保存和显示NSAttributed字符串。使用NSMutableAttributeString,可以使每个字母具有不同的颜色 因此,从两个标签开始,一个在另一个的正上方(即在它前面,隐藏它),具有相同的文本但不同的字母颜色。现在将顶部1的alpha衰减为零,从而逐渐显示其后面的

我正在尝试复制机密应用程序的文本标签转换。有人知道最好的方法吗

看起来他们让每个字母以明文颜色开始,然后将其动画化为灰色,然后是白色文本颜色

以下是一些屏幕截图: 这里有一个可能的方法

首先,让我们注意到UILabel可以保存和显示NSAttributed字符串。使用NSMutableAttributeString,可以使每个字母具有不同的颜色


因此,从两个标签开始,一个在另一个的正上方(即在它前面,隐藏它),具有相同的文本但不同的字母颜色。现在将顶部1的alpha衰减为零,从而逐渐显示其后面的一个。因此,每个字母似乎都会逐渐呈现其背后字母的颜色。

我只想用一个简单的例子来说明@matt所说的内容。从两个标签开始,一个标签直接位于另一个标签的顶部,具有相同的属性和路线。在两个标签都配置好并准备好设置动画后,您所要做的就是淡出顶部标签

- (void)awakeFromNib
{
    [super awakeFromNib];

    [self.view setBackgroundColor:[UIColor blackColor]];

    NSString *text = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 100.0, 320.0, 200.0)];
    [label1 setNumberOfLines:0];
    [label1 setBackgroundColor:[UIColor clearColor]];
    [label1 setAttributedText:[self randomlyFadedAttStringFromString:text]];
    [self.view addSubview:label1];

    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 100.0, 320.0, 200.0)];
    [label2 setNumberOfLines:0];
    [label2 setBackgroundColor:[UIColor clearColor]];
    [label2 setTextColor:[UIColor whiteColor]];
    [label2 setAttributedText:[[NSAttributedString alloc] initWithString:text]];
    [self.view addSubview:label2];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:1.0 animations:^{
            [label2 setAlpha:0.0];
        } completion:^(BOOL finished) {
            [label2 removeFromSuperview];
        }];
    });
}
然后为底部标签创建一个特殊的属性字符串。此属性化字符串不应修改除
NSForegroundColorAttributeName
属性之外在其他标签上设置的任何属性。您可能想也可能不想想出某种算法来确定哪些字母应该褪色多少,但下面的代码将从输入字符串生成一个属性字符串,其中每个字母alpha只是0到1之间的随机值

- (NSAttributedString *)randomlyFadedAttStringFromString:(NSString *)string
{
    NSMutableAttributedString *outString = [[NSMutableAttributedString alloc] initWithString:string];

    for (NSUInteger i = 0; i < string.length; i ++) {
        UIColor *color = [UIColor colorWithWhite:1.0 alpha:arc4random_uniform(100) / 100.0];
        [outString addAttribute:NSForegroundColorAttributeName value:(id)color range:NSMakeRange(i, 1)];
    }

    return [outString copy];
}
-(NSAttributedString*)随机FadedAttStringFromString:(NSString*)字符串
{
NSMutableAttributedString*outString=[[NSMutableAttributedString alloc]initWithString:string];
for(整数i=0;i
谢谢大家的帮助。我能够通过一些修改来保持标签一次又一次的褪色。这是我的完整源代码:

这是另一个解决方案


我使用CADisplayLink和NSAttributedString,这样我们只需要一个UILabel,看看:)

谢谢!好主意。我以前从未与CADisplayLink合作过。