patchthecode / JTAppleCalendar

The Unofficial Apple iOS Swift Calendar View. Swift calendar Library. iOS calendar Control. 100% Customizable
https://patchthecode.com
MIT License
7.57k stars 808 forks source link

Calendar View scroll to first month when i change height of calendar view #597

Closed hoanganhbk94 closed 7 years ago

hoanganhbk94 commented 7 years ago

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 !!!

patchthecode commented 7 years ago

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?

hoanganhbk94 commented 7 years ago

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!

patchthecode commented 7 years ago

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

         }
hoanganhbk94 commented 7 years ago

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

patchthecode commented 7 years ago
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.

spensko commented 7 years ago

@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() }

patchthecode commented 7 years ago

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

Let me know

spensko commented 7 years ago

@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

patchthecode commented 7 years ago

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

spensko commented 7 years ago

@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

patchthecode commented 7 years ago

thank you. Send me the sample test project. I will look into it. patchthecode@gmail.com

spensko commented 7 years ago

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

patchthecode commented 7 years ago

@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.

spensko commented 7 years ago

@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

patchthecode commented 7 years ago

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.

dev-fuad commented 6 years ago

@patchthecode Did you make the tutorial?

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

minseungseon commented 3 years ago

I'm facing similar issues. Is there any code that helped this kind of situation? :) @patchthecode

patchthecode commented 3 years ago

https://patchthecode.com/jtapplecalendar-home/week-view-month-view/ ?