Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore state after application enters background. #38

Closed
iambenmitchell opened this issue Oct 7, 2018 · 3 comments
Closed

Restore state after application enters background. #38

iambenmitchell opened this issue Oct 7, 2018 · 3 comments

Comments

@iambenmitchell
Copy link

Wherever someone leaves my app and lets it go into the background, when they then later open the app, the gradient is no longer cycling.

Is there away to restore the state the gradient was in before being sent to background?

thank you.

I think I should be able to do it with func applicationDidBecomeActive(_ application: UIApplication) { but I don't know how

@iambenmitchell
Copy link
Author

override func viewDidLoad() {
    super.viewDidLoad()
    gradient()
    NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.willEnterForegroundNotification
        , object: nil)

}

@objc func willEnterForeground() {
    print("test")
    gradient()
}

func gradient(){
    let pastelView = PastelView(frame: view.bounds)
    
    // Custom Direction
    pastelView.startPastelPoint = .bottomLeft
    pastelView.endPastelPoint = .topRight
    
    // Custom Duration
    pastelView.animationDuration = 1.5
    
    // Custom Color
    pastelView.setColors([UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
                          UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
                          UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
                          UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1.0),
                          UIColor(red: 32/255, green: 158/255, blue: 255/255, alpha: 1.0),
                          UIColor(red: 90/255, green: 120/255, blue: 127/255, alpha: 1.0),
                          UIColor(red: 58/255, green: 255/255, blue: 217/255, alpha: 1.0)])
    
    
    pastelView.startAnimation()
    view.insertSubview(pastelView, at: 0)
    print("Test1")
}

"Test" and "Test1" are printed to the console yet the application refuses to resume the gradient

@dannmat
Copy link

dannmat commented Jan 11, 2019

Also have this issue

@kaseyb002
Copy link

kaseyb002 commented Nov 2, 2019

@MrBenFTW
You're inserting a new pastelView behind the ones that are already in there each time you call gradient().

view.insertSubview(pastelView, at: 0)

I'd just keep a reference to pastelView and reinit each time. Add it to the main view only once.

// View Controller property
private lazy var pastelView = PastelView(frame: view.bounds)

func restartPastel() {
    pastelView = PastelView(frame: view.bounds)
    pastelView.startAnimation()
}

@objc func willEnterForeground() {
    restartPastel()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants