Giter Club home page Giter Club logo

eastereggsanimation's Introduction

EasterEggsAnimation

Description

EasterEggsAnimation is a convenient way to decorate the entire screen of your application or a separate view by adding beautiful endless animation. This library allows you to add your own images, enable their animation, specify animation speed and conveniently set specific dates when this decorative addition will be displayed in your application. The library has the ability to conveniently integrate it both into a project written in UIKit and in SwiftUI.

Simulator.Screen.Recording.-.iPhone.13.mini.-.2024-02-13.at.18.17.55.mp4

Usage example in UIKit

Below is an example of the most basic use of AnimatedView, where only an image is passed to the initializer as an argument

import UIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let animatedView = AnimatedView(patternImage: UIImage(named: "pattern"))
        animatedView.frame = self.view.bounds
        
        self.view.addSubview(animatedView)
        
        animatedView.animate()
    }
}

If necessary, you can specify one of the additional parameters - the speed of the animation or the date when the animation should be played:

let animatedView = AnimatedView(patternImage: UIImage(named: "pattern"), divider: 1500)

patternImage - image of UIImage type

IMPORTANT: to create the effect of an “endless” image, it is recommended to choose a so-called “pattern” as an image - an image that can be laid in tiles and it will dock with itself

divider - a number indicating which part of the side (height or width) of the parent view the picture will be shifted to the next time the frame is updated. Thus, the larger the number specified, the smaller the distance the image will be shifted on the next frame and, accordingly, the longer one animation cycle will be, i.e. the animation itself is slower. The default number is 1000

let animatedView = AnimatedView(patternImage: UIImage(named: "pattern"), dates: ["2024/12/25"])

dates - an array of dates, presented as a string in the format YYYY/MM/dd. When you specify this parameter, AnimatedView content will only be displayed on the specified date. By default this array is empty and the contents are displayed on any day

IMPORTANT: to start animation, you must call the animemate() method as indicated in the example:

animatedView.animate()

Otherwise your image will appear static

Usage example in SwiftUI

Below is an example of the most basic use of RepresentedAnimatedView, where only an image is passed to the initializer as an argument

import SwiftUI

struct ContentView: View {
    
    @State private var currentOfset = CGPoint(x: 0.0, y: 0.0)
    
    var body: some View {
        let animatedView = RepresentedAnimatedView(
            patternImage: UIImage(named: "pattern"),
            divider: 1500,
            dates: ["2024/02/13"],
            offset: self.$currentOfset
        )
        
        animatedView.animate()
        
        return ZStack {
            VStack {
                Image(systemName: "globe")
                    .imageScale(.large)
                    .foregroundStyle(.tint)
                Text("Hello, world!")
            }
            .padding()

            animatedView
                .ignoresSafeArea()
                .disabled(true)
        }
    }
}

#Preview {
    ContentView()
}

RepresentedAnimatedView has an initializer with four arguments, two of which are a divider and dates, which are optional.

let animatedView = RepresentedAnimatedView(patternImage: UIImage(named: "pattern"), divider: 1500, dates: ["2024/12/25", "2025/01/01"], offset: self.$currentOfset)

The purpose of the first three arguments is described above in the section on using the library in UIKit.

offset is a state variable of type SGPoint, which indicates the initial position of the image relative to its own frame (in most cases this is CGPoint(x: 0.0, y: 0.0)):

@State private var currentOfset = CGPoint(x: 0.0, y: 0.0)

IMPORTANT: to start animation on the created instance of RepresentedAnimatedView, call the animate() method as shown in the example above:

animatedView.animate()

IMPORTANT: to maintain the ability to interact with controls that are under the RepresentedAnimatedView, add the .disabled modifier, as indicated in the example above:

animatedView
    .ignoresSafeArea()
    .disabled(true)

Requirements

iOS 15+, Swift 5.5

Installation

EasterEggsAnimation is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "EasterEggsAnimation"

License

EasterEggsAnimation is available under the MIT license. See the LICENSE file for more info.

eastereggsanimation's People

Contributors

ermakovaleks avatar zsonz avatar

Stargazers

 avatar Eugene Kotsogub avatar

Watchers

Oleksa Korin avatar Kovalyov Anton avatar Igor Matviichuk avatar Eugene Kotsogub avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.