如果您第一次看到图片,我的问题将会被清楚地理解: 在第一张图片中,所选日期为3月2日
但是当我尝试选择二月的28或29时,而不是停留在同一周,它会移动到前一周。请看第二张图片。
我该如何避免? 以下是框架模块本身的一些代码:
- (void)viewDidScroll
{
if(self.contentSize.width <= 0){
return;
}
CGSize size = self.frame.size;
switch (_pageMode) {
case JTCalendarPageModeFull:
if(self.contentOffset.x < size.width / 2.){
[self loadPreviousPage];
}
else if(self.contentOffset.x > size.width * 1.5){
[self loadNextPage];
}
break;
case JTCalendarPageModeCenter:
break;
case JTCalendarPageModeCenterLeft:
if(self.contentOffset.x < size.width / 2.){
[self loadPreviousPage];
}
break;
case JTCalendarPageModeCenterRight:
if(self.contentOffset.x > size.width / 2.){
[self loadNextPage];
}
break;
}
[_manager.scrollManager updateMenuContentOffset:(self.contentOffset.x / self.contentSize.width) pageMode:_pageMode];
}
- (void)loadPreviousPage
{
NSDate *nextDate = [_manager.delegateManager dateForPreviousPageWithCurrentDate:_leftView.date];
// Must be set before chaging date for PageView for updating day views
self->_date = _leftView.date;
UIView<JTCalendarPage> *tmpView = _rightView;
_rightView = _centerView;
_centerView = _leftView;
_leftView = tmpView;
_leftView.date = nextDate;
[self updateMenuDates];
JTCalendarPageMode previousPageMode = _pageMode;
[self updatePageMode];
CGSize size = self.frame.size;
switch (_pageMode) {
case JTCalendarPageModeFull:
_leftView.frame = CGRectMake(0, 0, size.width, size.height);
_centerView.frame = CGRectMake(size.width, 0, size.width, size.height);
_rightView.frame = CGRectMake(size.width * 2, 0, size.width, size.height);
if(previousPageMode == JTCalendarPageModeFull){
self.contentOffset = CGPointMake(self.contentOffset.x + size.width, 0);
}
else if(previousPageMode == JTCalendarPageModeCenterLeft){
self.contentOffset = CGPointMake(self.contentOffset.x + size.width, 0);
}
self.contentSize = CGSizeMake(size.width * 3, size.height);
break;
case JTCalendarPageModeCenter:
// Not tested
_leftView.frame = CGRectMake(- size.width, 0, size.width, size.height);
_centerView.frame = CGRectMake(0, 0, size.width, size.height);
_rightView.frame = CGRectMake(size.width, 0, size.width, size.height);
self.contentSize = size;
break;
case JTCalendarPageModeCenterLeft:
_leftView.frame = CGRectMake(0, 0, size.width, size.height);
_centerView.frame = CGRectMake(size.width, 0, size.width, size.height);
_rightView.frame = CGRectMake(size.width * 2, 0, size.width, size.height);
self.contentOffset = CGPointMake(self.contentOffset.x + size.width, 0);
self.contentSize = CGSizeMake(size.width * 2, size.height);
break;
case JTCalendarPageModeCenterRight:
_leftView.frame = CGRectMake(- size.width, 0, size.width, size.height);
_centerView.frame = CGRectMake(0, 0, size.width, size.height);
_rightView.frame = CGRectMake(size.width, 0, size.width, size.height);
self.contentSize = CGSizeMake(size.width * 2, size.height);
break;
}
// Update dayViews becuase current month changed
[_rightView reload];
[_centerView reload];
if(_manager.delegate && [_manager.delegate respondsToSelector:@selector(calendarDidLoadPreviousPage:)]){
[_manager.delegate calendarDidLoadPreviousPage:_manager];
}
}