PaoloCuscela / Cards

Awesome iOS 11 appstore cards in swift 5.
MIT License
4.21k stars 275 forks source link

Card Animation Return Glitchy #56

Closed elitebyte closed 6 years ago

elitebyte commented 6 years ago

ezgif com-optimize

When creating a Card on my own application as well as running the demo project I noticed that whenever one "swipes away" a Card it goes to the top left corner of the display for about 2 seconds and then returns abruptly to it's original position. Is this intentional? or am I the only one experiencing this?

Edit: I added a gif to show this in action. Also, this same bug persists inside both the emulator, real device (iPhone 7 iOS 12). And I even downloaded your demo project to see if it was just my implementation but the problem exists in the demo as well. It happens everytime and it looks terrible, thinking of removing the whole card functionality and just have it segue into another ViewController at this point.

Nerkyator commented 6 years ago

I'have the same issue. It doesn't happen everytime so is hard to catch where and when it appears but I confirm. The only thing I noticed is that (for me) happens only on a real device, never on simulator.

Nerkyator commented 6 years ago

It seems that on your side is quite easy to reproduce the issue but on my project(s) it's really random. The only thing I found with lot of tries is: Open the CardHighlight detail Scroll to bottom to let close button appear While scrolling animation is still in progress (bouncing or scrolling) push the close button With these steps the bug always appears (little different because the card goes on the top center instead top left). I'm trying to figure out but it seems to be not so easy :(

elitebyte commented 6 years ago

@walterkyo Thank you for your advice, unfortunately the problem still persists and I made sure to clean+build my project to make sure the dependencies were rebuilt using the modifications. But no cigar, any ideas? Also what's the best way to go about debugging this issue?

Edit: Whenever the card is dropped back down I get this printed in my console "(0.0, 0.0, 375.0, 812.0)" seems like a CGRect print out but the only thing is that my card's frame is 300x300 nowhere near the 812. Also not sure where this print out is coming from.

Nerkyator commented 6 years ago

@walterkyo Same as EliteByte said: I added your modifications to a fresh download of Cards and nothing changes. Well, actually the only thing changing is that on back animation the background is black and returns white once animation is finished (so worst than before 😅)

@EliteByte the print you see comes from print(scrollView.frame). It is located in layout func, in DetailViewController class 😊

elitebyte commented 6 years ago

@Nerkyator Yah I just realized that it made the problem worse lol. And also did find the line where that's being printed. Seems pretty extraneuous usually random print's like that are taken out of final builds as it doesn't seem to have any functionality.

Any thoughts though on getting this fixed? This has been buggin' me for the past week (no pun intented). The problem would have to exist within the Animations.swift file right? I'm not sure which function/class is triggered when the Card is pushed back.

Nerkyator commented 6 years ago

@walterkyo: Just tried your modifications. I can't reproduce easily the bug described by @EliteByte (happens scrolling down the DetailViewController to close it) so I don't know if your edit fixed it. I think we have to wait for him to try it. I tried using the close button (as described few comments above) and the bug still persists :(

walterkyo commented 6 years ago

@Nerkyator by more testing my code does not fix the "fast scrolling + dismiss cardview" bug. But it looks like a little bit better. The "fast scrolling + dismiss" problem is probably due to the card frame position.

in Card.swift //Change this variable to public open var originalFrame = CGRect.zero

in HighlightViewController.swift //Update card frame override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews()

    if let superview = first.superview {
        first.originalFrame = superview.convert(first.frame, to: nil)
    }

    if let superview = second.superview {
        second.originalFrame = superview.convert(second.frame, to: nil)
    }
}

in Animator.swift guard presenting else { ... //Change (card.backgroundIV.frame, to: card.originalFrame) to (card.originalFrame, to: card.originalFrame) let bounce = self.bounceTransform(card.originalFrame, to: card.originalFrame) }

private func bounceTransform(_ from: CGRect, to: CGRect ) -> CGAffineTransform { //Change .center to .origin let old = from.origin let new = to.origin }

in DetailViewController.swift if let detail = detailView { //Add this detail.frame = self.view.bounds

        scrollView.addSubview(detail)
        detail.alpha = 0
        detail.autoresizingMask = .flexibleWidth
    }

//Update detail frame, blurView frame, scrollView frame, card.backgroundIV frame, originalFrame here override func viewWillLayoutSubviews() { super.viewWillLayoutSubviews() if isShowing{ let screenSize = UIScreen.main.bounds self.view.frame.size = CGSize(width: screenSize.width, height: screenSize.height)

        blurView.frame = self.view.bounds

        card.superVC?.viewWillLayoutSubviews()

        scrollView.frame.size = CGSize(width: LayoutHelper.editedXScreen(85, view: self.view), height: LayoutHelper.editedYScreen(100, view: self.view) - 20)

        scrollView.center = blurView.center
        scrollView.frame.origin.y = 40

        card.backgroundIV.frame.origin = scrollView.bounds.origin
        card.backgroundIV.frame.size = CGSize( width: scrollView.bounds.width,
                                               height: card.backgroundIV.bounds.height)

        originalFrame = scrollView.frame

        if let detail = detailView {
            detail.frame = CGRect(x: 0,
                                  y: card.backgroundIV.bounds.maxY,
                                  width: scrollView.frame.width,
                                  height: screenSize.height)
            scrollView.contentSize = CGSize(width: scrollView.bounds.width, height: detail.frame.maxY)
        }
    }
}

in LayoutHelper.swift //this one is optional for device rotation issue static func editedXScreen(_ percentage: CGFloat, view: UIView) -> CGFloat { return percentage * view.bounds.width / 100 }

static func editedYScreen(_ percentage: CGFloat, view: UIView) -> CGFloat {
    return percentage * view.bounds.height / 100
}
PaoloCuscela commented 6 years ago

I've found where the problem was. It was caused by a strange behavior of the DetailViewController's ScrollView. I should have fixed that, try with the latest update and let me know ;D

jondwillis commented 6 years ago

@walterkyo you could fork the project and commit those changes and submit a pull request.

elitebyte commented 6 years ago

@jondwillis The changes Walter made actually made the problems worse, wouldn't recommend.

Nerkyator commented 6 years ago

Just tried with latest release and bug is still present. After few tries it seems that you can reproduce the problem if you dismiss detailViewController panning from its internal scrollView. It doesn't happen everytime unfortunately :( I used CardGroup demo on an iPhone 8 Simulator

akring commented 6 years ago

Same problem here. Happens on cards with detail view controller.

I just tried the demo and we can reproduce it on all the cards in demo.

Device: iPhone 8 OS: iOS 12 Public Beta (a6A5345f)

PaoloCuscela commented 6 years ago

I managed to solve the rotation glitch in non-fullscreen cards just by switching

scrollView.frame.size = CGSize(width: LayoutHelper.YScreen(90), height: LayoutHelper.XScreen(100) - 20)

in DetailViewController -> layout()

For the disappearing cards on close I can't replicate it on iPhone 6s + simulator. Pushing the latest changes, let me know...

akring commented 6 years ago

Not resolved, still can reproduce it on all kinds of devices running iOS 12. This bug seems only occurs on iOS 12 devices.

eeschiavo commented 6 years ago

I have the same problem, any solution? Thanks

Michele404 commented 6 years ago

Same problem

Michele404 commented 6 years ago

@walterkyo can you rewrite a better tutorial?

Anyone404 commented 6 years ago

upp

amerhukic commented 6 years ago

@PaoloCuscela I've created a pull request that should fix this issue.

akring commented 6 years ago

@amerhukic Thank you for your PR but problem still not resolved, this bug is iOS 12 only, and we still can reproduce it with official demo.

Michele404 commented 6 years ago

The demo is fixxed as I can see, I can’t reproduce the bug. It was on iOS 11+ too and I don’t got it at the moment, I’ll test with iOS 12 today

Michele404 commented 6 years ago

Ios12 full bug

federico2390 commented 6 years ago

same bug on iOS 12 when release a fix for cards? please

jondwillis commented 6 years ago

Assuming this is fixed by @amerhukic 's PR that was merged. The fix is in master, but there has not yet been a release published. However, if you are using Cocoapods, you may pull in the hotfix by:

pod 'Cards', :git => 'https://github.com/PaoloCuscela/Cards.git'

Michele404 commented 6 years ago

Its not fixxed on iOS12.

junaidxabd commented 6 years ago

I'm still getting the glitchy animations with the Demo project in iOS 12

PaoloCuscela commented 6 years ago

80