Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add slide to unlock effect to a UITextView or UILabel?

Tags:

ios

I have a large text and want to add an effect that is similar to the slide to unlock one of the latest iOS and that will go from top to bottom with the text sliding from bottom to top.

like image 979
Ravi Gupta Avatar asked Apr 16 '14 07:04

Ravi Gupta


2 Answers

Update with swift shimmering label, view etc...

import UIKit
import QuartzCore

class ViewController: UIViewController {

    @IBOutlet var testLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.testLabel.startShimmering()
    }
}

extension UIView {
    func startShimmering() {
        //        let light = UIColor.init(white: 0, alpha: 0.1).cgColor
        let light = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1).cgColor
        let dark = UIColor.black.cgColor

        let gradient: CAGradientLayer = CAGradientLayer()
        gradient.colors = [dark, light, dark]
        gradient.frame = CGRect(x: -self.bounds.size.width, y: 0, width: 3*self.bounds.size.width, height: self.bounds.size.height)
        gradient.startPoint = CGPoint(x: 0.0, y: 0.5)
        gradient.endPoint = CGPoint(x: 1.0, y: 0.525)
        gradient.locations = [0.4, 0.5, 0.6]
        self.layer.mask = gradient

        let animation: CABasicAnimation = CABasicAnimation(keyPath: "locations")
        animation.fromValue = [0.0, 0.1, 0.2]
        animation.toValue = [0.8, 0.9, 1.0]

        animation.duration = 1.5
        animation.repeatCount = HUGE
        gradient.add(animation, forKey: "shimmer")


    }

    func stopShimmering() {
        self.layer.mask = nil
    }

}
like image 139
Raj Joshi Avatar answered Nov 20 '22 05:11

Raj Joshi


I suggest you use Grant Pauls's Shimmer control, because it does just that.

https://github.com/facebook/Shimmer

example

like image 6
Finn Gaida Avatar answered Nov 20 '22 04:11

Finn Gaida