johnvuko / JTCalendar

A customizable calendar view for iOS.
MIT License
2.76k stars 534 forks source link

Months don't snap to their edge #207

Open jlindenbaum opened 9 years ago

jlindenbaum commented 9 years ago

When flicking the calendar left / right between months the calendar does not always properly stop at the month's edge, it can go further, or not far enough. This leads to the menu view and the calendar itself being in a weird state.

Simulator: 5S running 8.4 JTCalendar: 2.1.4

screen shot 2015-09-16 at 13 50 54

screen shot 2015-09-16 at 13 50 48

johnvuko commented 9 years ago

I remember having this bug but I don't remember how I solve it and what was it's origin, I think it's coming from the menu view or the synchronisation between the menu view and the calendar. Can you create a repository with a project with the same configuration?

ty-sang commented 9 years ago

Try [calendar reloadAppearance] and [calendar repositionViews] in viewDidLayoutSubviews, that solved my for me.

hope this will help

jlindenbaum commented 9 years ago

@jonathantribouharet I will try and spike this out into a separate project I can upload here. But the setup is basically as simple as your examples.

@shieer must be part of the 1.x versions, in 2.x those are not public selectors.

But, when I perform them regardless, it seems to lessen how often the problem appears, but the problem still persists frequently enough to be blocking me from updating.

- (void)viewDidLayoutSubviews {
    [_calendarMenu performSelector:@selector(repositionViews)];
    [_calendarContent performSelector:@selector(repositionViews)];
}
johnvuko commented 9 years ago

Yes it's from 1.x version, event if repositionViews method still exist, it's a full rewrite of the code. If I can't reproduce the bug it's complicated to fix it for me. I wait until you create a repository with just this controller for debug it.

ty-sang commented 9 years ago

it is 1.x version, sorry, i didn't see you are on 2.x

tomdalling commented 8 years ago

Just wanted to "plus one" this and say that I've hit the same bug. I've tried to create a minimal reproducible example project, but I can't trigger the bug outside of my app.

palcalde commented 8 years ago

@tomdalling @shieer @jlindenbaum check the pullrequest: #218. Hopefully works for your projects.

jlindenbaum commented 8 years ago

@palcalde I've replaced your fixes in my JTHorizontalCalendar - it doesn't seem to address the fix - I can go correctly in one direction, but after one or two swipes in the other direction the same issue reappears.

tomdalling commented 8 years ago

Here's a minimal reproduction project that shows the issue (see the README): https://github.com/tomdalling/JTCalendarBugReproduction

I tried PR #218, and it mostly works. It causes some weirdness when repeatedly tapping the "Next Month" button in the JTCalendarBugReproduction project. Tapping "Next Month" while the sliding animation is in progress slows down the animation.

I'm not sure if it fixes the exact issue I was having in my app. Some recent unrelated changes to my app seem to have made the bug disappear, although I'm not sure why.

palcalde commented 8 years ago

Hey @tomdalling you are right, tapping multiple times on back works great but doing it in next month slows down the animation (at least doesn't break the calendar as before).

I've udpated the #218 with a new commit that allows tapping on next multiple times without slowing the animation. Check it out.

johnvuko commented 8 years ago

@tomdalling Thank you very much, I wasn't able to reproduce the bug.

I still don't know what exactly is the problem. I think it's when there is an interaction during the animation of the scrollview.

I may have a simple / dirty hack, after calling [_horizontalView loadPreviousPageWithAnimation]; or another method moving the scrollview call

[_horizontalView performSelector:@selector(repositionViews) withObject:nil];

This hack came from http://stackoverflow.com/questions/993280/how-to-detect-when-a-uiscrollview-has-finished-scrolling, I'm using it for UITableView in specific cases. It's call repositionViews method (which is not public) but in the main thread and after the animation of the scrollview (a the end of a scroll for example because the delegate method cannot be used in some cases...).

palcalde commented 8 years ago

I haven't found issues after applying the changes in #218.

veyhong commented 8 years ago

Hi there, I have add some code it help a lot to let Months snap to their edge. Please help check I am not sure wether it will solve all problem or not, but after add this lines, I rarely see the problem or maybe I cannot reproduce the bug ? link: https://github.com/cvhong/JTCalendar/commit/350183375ca99d4199c39da7adceb5be5a9aa4cb

lefty1 commented 8 years ago

I get the problem as well. It happens when I call loadNextPageWithAnimation serveral time rapidly in succesion. The bug seem to be with the calculation of contentOffset. I figured out a temporary workaround anyway.