cruisediary / Pastel

🎨 Gradient animation effect like Instagram
MIT License
3.5k stars 185 forks source link

Animation stops when returns to view using Navigation Bar #21

Open junaidxabd opened 7 years ago

junaidxabd commented 7 years ago

If you press back to go back to the view with the animation (in the navigation controller stack) the animation doesn’t work.

Xopoko commented 7 years ago

Same problem, swipe to back, too

chrismgala commented 7 years ago

Having the same problem as well. Tried moving the code from viewDidLoad to viewWillAppear as that is called each time the view is reloaded but didn't help.

dopefaceee commented 6 years ago

anyone resolve the issue ?

sblatz commented 6 years ago

Bump. Also having this issue whenever the view disappears and reappears (like upon minimizing the app and opening again).

DaveCC94 commented 6 years ago

I have some kind of workaround, but you may not like it.

In my case I created a subclass from UIButton, then I added the gradient there and unluckily for me I crossed with this issue, so what I did next is to override willMove like this

override func willMove(toWindow newWindow: UIWindow?) {
    if newWindow == nil {
        // We remove the view
        self.subviews[0].removeFromSuperview()
    } else {
        // Add we re-added the Pastel View here
    }
}

I personally don't like to mess with this methods because this can lead to some errors, but in this way we can remove the unmoving view and add it again.

Also, I didn't notice any significant memory leak, it spikes to 0.1MB when displayed and then it gets to 0 as soon as the PastelView is removed.

Umity commented 6 years ago

tried viewdidAppear but didnt help..

iambenmitchell commented 6 years ago
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" is printed to the console, yet the animation refuses to resume