我正在使用JTCalendar构建一个自定义日历应用程序,默认情况下,它被设置为水平滚动几个月。根据我的理解,将其设置为垂直滚动将需要以垂直方式列出内容(月份)。
JTcalendar的作者建议使用这,但还不清楚应该如何为此目的修改contentOffset。下面是包含contentOffset的函数
JTCalendar.m宪兵.m:
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
if(self.calendarAppearance.isWeekMode){
return;
}
if(sender == self.menuMonthsView && self.menuMonthsView.scrollEnabled){
self.contentView.contentOffset = CGPointMake(sender.contentOffset.x * calendarAppearance.ratioContentMenu, self.contentView.contentOffset.y);
}
else if(sender == self.contentView && self.contentView.scrollEnabled){
self.menuMonthsView.contentOffset = CGPointMake(sender.contentOffset.x / calendarAppearance.ratioContentMenu, self.menuMonthsView.contentOffset.y);
}
}JTCalendarContentView.m:
- (void)configureConstraintsForSubviews
{
self.contentOffset = CGPointMake(self.contentOffset.x, 0); // Prevent bug when contentOffset.y is negative
CGFloat x = 0;
CGFloat width = self.frame.size.width;
CGFloat height = self.frame.size.height;
for(UIView *view in monthsViews){
view.frame = CGRectMake(x, 0, width, height);
x = CGRectGetMaxX(view.frame);
}
self.contentSize = CGSizeMake(width * NUMBER_PAGES_LOADED, height);
}发布于 2015-06-22 22:14:43
在scrollViewDidScroll中:
这一行:
CGPointMake(sender.contentOffset.x * calendarAppearance.ratioContentMenu, self.contentView.contentOffset.y);应该是这样的:
CGPointMake(sender.contentOffset.x, self.contentView.contentOffset.y * calendarAppearance.ratioContentMenu);这一行:
self.menuMonthsView.contentOffset = CGPointMake(sender.contentOffset.x / calendarAppearance.ratioContentMenu, self.menuMonthsView.contentOffset.y);应该是这样的:
self.menuMonthsView.contentOffset = CGPointMake(sender.contentOffset.x, self.menuMonthsView.contentOffset.y / calendarAppearance.ratioContentMenu);在configureConstraintsForSubviews中,有一些地方可能需要修改。不确定下面的行,因为它被设置为修复特定的错误,所以您现在可以注释掉它,看看会发生什么:
// Probably comment this out
self.contentOffset = CGPointMake(self.contentOffset.x, 0); // Prevent bug when contentOffset.y is negative这段代码:
for(UIView *view in monthsViews){
view.frame = CGRectMake(x, 0, width, height);
x = CGRectGetMaxX(view.frame);
}应该是这样的:(将x变量重命名为y)
for(UIView *view in monthsViews){
view.frame = CGRectMake(0, y, width, height);
y = CGRectGetMaxY(view.frame);
}最后,这一行:
self.contentSize = CGSizeMake(width * NUMBER_PAGES_LOADED, height);可能应该是:
self.contentSize = CGSizeMake(width, height * NUMBER_PAGES_LOADED);我没有测试其中的任何一个,但是基于您发布的代码以及我在过去使用过JTCal的事实,这将使您走上正确的道路。
https://stackoverflow.com/questions/30989973
复制相似问题