iPhone “slide to unlock” animation

前端 未结 13 789
感情败类
感情败类 2020-11-28 00:49

Any ideas as to how Apple implemented the \"slide to unlock\" (also, \"slide to power off\" is another identical example) animation?

I thought about some sort of ani

13条回答
  •  失恋的感觉
    2020-11-28 01:19

    You can use the kCGTextClip drawing mode to set the clipping path and then fill with a gradient.

    // Get Context
    CGContextRef context = UIGraphicsGetCurrentContext();
    // Set Font
    CGContextSelectFont(context, "Helvetica", 24.0, kCGEncodingMacRoman);
    // Set Text Matrix
    CGAffineTransform xform = CGAffineTransformMake(1.0,  0.0,
                                                    0.0, -1.0,
                                                    0.0,  0.0);
    CGContextSetTextMatrix(context, xform);
    // Set Drawing Mode to set clipping path
    CGContextSetTextDrawingMode (context, kCGTextClip);
    // Draw Text
    CGContextShowTextAtPoint (context, 0, 20, "Gradient", strlen("Gradient")); 
    // Calculate Text width
    CGPoint textEnd = CGContextGetTextPosition(context);
    // Generate Gradient locations & colors
    size_t num_locations = 3;
    CGFloat locations[3] = { 0.3, 0.5, 0.6 };
    CGFloat components[12] = { 
        1.0, 1.0, 1.0, 0.5,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 0.5,
    };
    // Load Colorspace
    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
    // Create Gradient
    CGGradientRef gradient = CGGradientCreateWithColorComponents (colorspace, components,
                                                                  locations, num_locations);
    // Draw Gradient (using clipping path
    CGContextDrawLinearGradient (context, gradient, rect.origin, textEnd, 0);
    // Cleanup (exercise for reader)
    

    Setup an NSTimer and vary the values in locations, or use CoreAnimation to do the same.

提交回复
热议问题