Jtapplecalendar: Calendar View scroll to first month when i change height of calendar view

Created on 23 Oct 2017  路  16Comments  路  Source: patchthecode/JTAppleCalendar

I am using new version of calendar view. When i click a cell in calendar, if the cell has special event, i will change height of calendar view to show detail event. But calendar view scroll to first month. I don't know the reason. Help me, please !!!

Most helpful comment

@patchthecode
Did you make the tutorial?

I'm making a calendar view that change height on PanGesture. And facing the same issue.

All 16 comments

If you change the height of the calendar it will scroll to the first month.
You can change the height and anchor a date so that it will not scroll.

can you show me the code you are using to change the height of the calendar?

screen shot 2017-10-23 at 11 46 57 am
Thanks @patchthecode rep, heightEventViewConstraint is height of detail view. i make auto layout between calendar view and detail view. When height of detail view change => size of calendar view change too. Do you give me a solution to solve this!

I am not sure what you are trying to do.
But maybe this code below helps?

        UIView.animate(withDuration: 0.25, animations: {
            self.heightEventViewConstraint.constant = (cell as! CalendarCell).isEvent ? 100.0 : 0.0
            self.calendarView.alpha = 0
            self.view.layoutIfNeeded()
        }) { (endVal) in

            self.calendarView.reloadData(withanchor: date)
        }

        UIView.animate(withDuration: 1, animations: {
            self.calendarView.alpha = 1.0
        }) { (endVal) in

         }

Thanks for your reply but it isn't working. I upload my project to github.
Do you check for me?
https://github.com/hoanganhbk94/CalendarDemo

UIView.animate(withDuration: 0.25, animations: {
            self.heightEventViewConstraint.constant = (cell as! CalendarCell).isEvent ? 100.0 : 0.0
            self.calendarView.alpha = 0
            self.calendarView.reloadData(withanchor: date)
            self.view.layoutIfNeeded()
        }) { (endVal) in


        }

        UIView.animate(withDuration: 1, animations: {
            self.calendarView.alpha = 1.0
        }) { (endVal) in

         }

I got very busy over the last couple days.
Try this. If this does not work, I will do a tutorial on this as many developers have asked how to do this.

@patchthecode Hi! Thanks for this great library!

I have the same issue - calendar's superview bottom constraint is attached to some details view which expands on range selection. After selecting of a second date calendar scrolls up to beginning without animations

I've tried code from above but does not work for me

UIView.animate(withDuration: 0.3, animations: { self.detailsHeight.constant = 150 self.calendarView.reloadData(withanchor: <my_second_date>) self.view.layoutIfNeeded() }

@spensko does this demo help you?
It does a resize and does not restart ->
https://github.com/patchthecode/WLAppleCalendar

Let me know

@patchthecode demo looks ok but i can't figure out what i need to setup for such behaviour

short video about issue
https://youtu.be/hELmIM9tvVk

@spensko
I looked at the video, But I am not understand how you want the calendar to behave.

@patchthecode long story short. if I changing some constraint which cause the calendar to change its height then the calendar resets to the beginning

I will make clean project for tests

thank you.
Send me the sample test project. I will look into it.
[email protected]

@patchthecode sended. in this sample calendar resets after deselection while changing constraint of the blue bottom view

@spensko

Ok. I see what you are doing.
You have changed the height of the calendar.

The will cause the layout to be invalidated.
Which will then cause the calendar to scroll to the beginning. This is normal for any UICollectionView.

Since I am getting many questions on animation, I will do a tutorial on this.

@patchthecode since I don't need to animate change of the height of the calendar, I've anchored it to bottom of controller and change contentInset. so this issue is resolved for me :)

@hoanganhbk94

thanks for letting me know.
In the mean time, i'm doing a tutorial on animation and height change, so that people have a clear idea what to do here. Thanks for make me aware of the difficulty.

@patchthecode
Did you make the tutorial?

I'm making a calendar view that change height on PanGesture. And facing the same issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

programus picture programus  路  3Comments

zhanswift picture zhanswift  路  5Comments

sahirmemon picture sahirmemon  路  4Comments

carlosper88 picture carlosper88  路  4Comments

prahaladm picture prahaladm  路  3Comments