Pastel icon indicating copy to clipboard operation
Pastel copied to clipboard

Animation stops when returns to view using Navigation Bar

Open junaidxabd opened this issue 7 years ago • 7 comments

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

junaidxabd avatar Jun 10 '17 20:06 junaidxabd

Same problem, swipe to back, too

Xopoko avatar Sep 20 '17 16:09 Xopoko

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.

chrismgala avatar Sep 25 '17 04:09 chrismgala

anyone resolve the issue ?

dopefaceee avatar Feb 01 '18 16:02 dopefaceee

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

sblatz avatar Feb 06 '18 18:02 sblatz

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.

DaveCC94 avatar Feb 11 '18 05:02 DaveCC94

tried viewdidAppear but didnt help..

Umity avatar Apr 23 '18 21:04 Umity

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

iambenmitchell avatar Oct 08 '18 17:10 iambenmitchell