We're sunsetting PodQuest on 2025-07-28. Thank you for your support!
Export Podcast Subscriptions
cover of episode 731. Pro iOS Table Views and Collection Views-代码介绍16

731. Pro iOS Table Views and Collection Views-代码介绍16

2016/9/2
logo of podcast iOSDevLog

iOSDevLog

Shownotes Transcript

Collection View Custom LayoutsImplementing the Layout FunctionsAs well as the custom functions needed to calculate the placement of the numerals and hands, there are a number of UICollectionViewLayout functions that you will need to implement.Let’s start the process of building the custom layout by implementing the following: prepareLayout collectionViewContentSize layoutAttributesForElementsInRect:  layoutAttributesForItemAtIndexPath:Let’s break these calculations down into four stages: A “master” function called calculateAllAttributes that iterates across the entire data model and calls the appropriate function to calculate the attributes for each date item in turn. A function called calculateAttributesForItemAtIndexPath that takes the indexPath for a data item, and calls the appropriate calculation function depending on the type of item (hour, minute, or second hand) or hour label. A function to calculate the position of the three hand cells:calculate AttributesForHandCellAtIndexPath: A function to calculate the position of the hour labels: calculateAttributesForHourLabelWithIndexPath: