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 807 forks source link

Animated transition from monthly to a weekly view #298

Closed numen31337 closed 7 years ago

numen31337 commented 7 years ago

Is there some way to make an animated transition from monthly to a weekly view, something like Apple Calendar do:

Animation Example

Thanks in advance

atereshkov commented 7 years ago

Hello. This library directly "out of the box" does not provide this functionality. I have not seen this in the documentation. Maybe @patchthecode can give u some advice.

patchthecode commented 7 years ago

@numen31337

@handioq is again correct. This library is is similar to a UITableView or a UICollectionView. You have to code exactly what you want. It does not come with animation out of the box.

Adding animation to views is very simple however. Just google search for the type of animation you wish to do and jus implement it.

I do have an example of an animation that is similar to the one what you want. [edit] download the sample app attached to this repository. Then just change the code in the following function to look like this:

func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleDayCellView?, cellState: CellState) {
        handleCellSelection(view: cell, cellState: cellState)
        handleCellTextColor(view: cell, cellState: cellState)

        // Add this new line of code to test
        calendar.fold(withTransparency: true, completionHandler: { 
            self.calendarView.isHidden = true
        }, inDirection: .closed)
        // _____________________
    }

Run the App and tap on a date and see what happens. You will get an animation. This is just an example. But you can code any animation you want.

numen31337 commented 7 years ago

@patchthecode Thank you for your effort

dilip-i commented 6 years ago

@numen31337 : Did u able to achieve this month view to week view and vice versa with the animation shown in the above video?Ijust want to knw if thts possible with this library

numen31337 commented 6 years ago

@dilip-i I'm sorry but I moved everything to the FSCalendar a long time ago, as it covers my needs a little bit more.

dilip-i commented 6 years ago

@numen31337 Thanks for the info.I needed a exact animation thing as in 'FSCalendar'.But unfortunately it doesnot give controls over the cell design.Can you suggest if you have other calendars with the same animation(week->month or vice versa)

numen31337 commented 6 years ago

@dilip-i My design is completely different, you can customize your design with a custom cell, check DIY Example https://github.com/WenchaoD/FSCalendar/blob/master/Example-Swift/FSCalendarSwiftExample/DIYCalendarCell.swift

patchthecode commented 6 years ago

@dilip-i animations like this are custom. And can be different to every developer. Animations like this do not depend on this library. They are just regular view animations. Therefore if you can do this animation for a regular UIView, then you can just need to replace the UIView, with a JTAppleCalendarView.

One of the easiest ways to do what ever crazy animation you want is by using view snap shots. This is explained here -> https://www.appcoda.com/view-animation-in-swift/ On that link scroll down till you find this text ->

We’ll use a feature introduced in iOS 7 called UIView snapshots to fix the animation. This allows you to take a snapshot of a UIView together with its hierarchy and render it into a new UIView.

Using this approach, you can take a snapshot of a UIView, animate it to your hearts content, and then show your weekView for the calendar.

dilip-i commented 6 years ago

@numen31337 @patchthecode : Thanks for your efforts, will try out this:)