1
我使用JTCalendar來構建一個自定義日曆應用程序,並且它被設置爲在默認情況下水平滾動瀏覽月份。根據我的理解,將其設置爲垂直滾動將需要以垂直方式佈置內容(月)。如何使UIScrollView的內容垂直滾動而不是水平滾動?
JTcalendar的作者建議this,但目前尚不清楚contentOffset
應該如何修改。這裏是包含contentOffset
功能:
JTCalendar.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);
}
這允許垂直滾動,但是當滾動停止時,日子消失。任何可能發生這種情況的原因? – TheDudeGuy