Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Fixed font won't update when scroll to item #73

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AKPickerViewSample/AKPickerView/AKPickerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ typedef NS_ENUM(NSInteger, AKPickerViewStyle) {
- (void)reloadData;
- (void)scrollToItem:(NSUInteger)item animated:(BOOL)animated;
- (void)selectItem:(NSUInteger)item animated:(BOOL)animated;
- (void)deselectItem:(NSUInteger)item;

@end
18 changes: 18 additions & 0 deletions AKPickerViewSample/AKPickerView/AKPickerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,19 @@ - (CGFloat)offsetForItem:(NSUInteger)item

- (void)scrollToItem:(NSUInteger)item animated:(BOOL)animated
{
/*
Fix when called in view did appear, font won't change if just
called `scrollToItemAtIndexPath:atScrollPosition:animated:` method,
this will force other cells on collection view reload their font.
*/
NSArray<NSIndexPath *> *indexPaths = [self.collectionView indexPathsForVisibleItems];
for (NSIndexPath *indexPath in indexPaths) {
AKCollectionViewCell *cell = (AKCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
if (indexPath.row != item) {
[cell setSelected:NO];
}
}

switch (self.pickerViewStyle) {
case AKPickerViewStyleFlat: {
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:item inSection:0]
Expand Down Expand Up @@ -246,6 +259,11 @@ - (void)selectItem:(NSUInteger)item animated:(BOOL)animated notifySelection:(BOO
[self.delegate pickerView:self didSelectItem:item];
}

- (void)deselectItem:(NSUInteger)item {
AKCollectionViewCell *cell = (AKCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:item inSection:0]];
[cell setSelected:NO];
}

- (void)didEndScrolling
{
switch (self.pickerViewStyle) {
Expand Down