Удержание и множественный выбор:
yourCalendarObject.swipeToChooseGesture.enabled = YES;
yourCalendarObject.allowsMultipleSelection = YES;
Удержание и одиночный выбор:
[yourCalendarObject setAllowsSelection: YES];
[yourCalendarObject setAllowsMultipleSelection: NO];
yourCalendarObject.swipeToChooseGesture.enabled = YES;
РЕДАКТИРОВАТЬ: для изменения действия касания или удержания FSCalendar не имеет этой функциональности, но вы можете добавить его с помощью одного свойства.
FSCalendar.h
Вам необходимо добавить это свойство в ваш заголовочный файл внутри:
@interface FSCalendar : UIView
/**
Difference the tap or hold gesture date selection
When the value = YES is a UILongPressGestureRecognizer
When the value = NO is a tap selection
*/
@property (readonly, nonatomic) BOOL isLongPressGesture;
@end
FSCalendar.m
Вам необходимо добавить установленное значение свойства в - (void) handleSwipeToChoose: (UILongPressGestureRecognizer *) pressGesture следующим образом:
- (void)handleSwipeToChoose:(UILongPressGestureRecognizer *)pressGesture
{
switch (pressGesture.state) {
case UIGestureRecognizerStateBegan:
case UIGestureRecognizerStateChanged: {
// New property value when the selection is UILongPressGestureRecognizer
_isLongPressGesture = YES;
NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:[pressGesture locationInView:self.collectionView]];
if (indexPath && ![indexPath isEqual:self.lastPressedIndexPath]) {
NSDate *date = [self.calculator dateForIndexPath:indexPath];
FSCalendarMonthPosition monthPosition = [self.calculator monthPositionForIndexPath:indexPath];
if (![self.selectedDates containsObject:date] && [self collectionView:self.collectionView shouldSelectItemAtIndexPath:indexPath]) {
[self selectDate:date scrollToDate:NO atMonthPosition:monthPosition];
[self collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
} else if (self.collectionView.allowsMultipleSelection && [self collectionView:self.collectionView shouldDeselectItemAtIndexPath:indexPath]) {
[self deselectDate:date];
[self collectionView:self.collectionView didDeselectItemAtIndexPath:indexPath];
}
}
self.lastPressedIndexPath = indexPath;
break;
}
case UIGestureRecognizerStateEnded:
case UIGestureRecognizerStateCancelled: {
self.lastPressedIndexPath = nil;
break;
}
default:
break;
}
}
Ну, вам нужно изменить метод - (void) collectionView: (UICollectionView *) collectionView didSelectItemAtIndexPath: (NSIndexPath *) indexPath следующим образом:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSDate *selectedDate = [self.calculator dateForIndexPath:indexPath];
FSCalendarMonthPosition monthPosition = [self.calculator monthPositionForIndexPath:indexPath];
FSCalendarCell *cell;
if (monthPosition == FSCalendarMonthPositionCurrent) {
cell = (FSCalendarCell *)[collectionView cellForItemAtIndexPath:indexPath];
} else {
cell = [self cellForDate:selectedDate atMonthPosition:FSCalendarMonthPositionCurrent];
NSIndexPath *indexPath = [collectionView indexPathForCell:cell];
if (indexPath) {
[collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
}
}
if (![_selectedDates containsObject:selectedDate]) {
cell.selected = YES;
[cell performSelecting];
}
[self enqueueSelectedDate:selectedDate];
[self.delegateProxy calendar:self didSelectDate:selectedDate atMonthPosition:monthPosition];
[self selectCounterpartDate:selectedDate];
// Reset the value of property
_isLongPressGesture = NO;
}
Так что вы можете попробовать это:
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition
{
if (calendar.isLongPressGesture)
NSLog(@"Long Press");
else
NSLog(@"Tap Gesture");
}
Наслаждайтесь кодом:)