Remove redundant properties and methods in FSCalendarHeaderView.

This commit is contained in:
WenchaoD 2018-10-09 17:28:01 +08:00
parent 4e6efb70f3
commit 252cd0e31f
4 changed files with 16 additions and 42 deletions

View File

@ -864,8 +864,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
_preferredWeekdayHeight = FSCalendarAutomaticDimension;
_preferredRowHeight = FSCalendarAutomaticDimension;
_preferredHeaderHeight = FSCalendarAutomaticDimension;
_calendarHeaderView.needsAdjustingMonthPosition = YES;
_calendarHeaderView.needsAdjustingViewFrame = YES;
[self setNeedsLayout];
}
}
@ -1506,7 +1504,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
_preferredWeekdayHeight = FSCalendarAutomaticDimension;
_preferredRowHeight = FSCalendarAutomaticDimension;
[self.calendarHeaderView setNeedsAdjustingViewFrame:YES];
[self setNeedsLayout];
}
@ -1527,7 +1524,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
[self requestBoundingDatesIfNecessary];
NSDate *targetPage = self.pagingEnabled?self.currentPage:(self.currentPage?:self.selectedDate);
[self scrollToPageForDate:targetPage animated:NO];
self.calendarHeaderView.needsAdjustingMonthPosition = YES;
}
- (BOOL)requestBoundingDatesIfNecessary

View File

@ -34,7 +34,6 @@
@property (readonly, nonatomic) UIView *bottomBorder;
@property (readonly, nonatomic) NSCalendar *gregorian;
@property (readonly, nonatomic) NSDateComponents *components;
@property (readonly, nonatomic) NSDateFormatter *formatter;
@property (readonly, nonatomic) UIView *contentView;

View File

@ -8,7 +8,6 @@
#import <UIKit/UIKit.h>
@class FSCalendar, FSCalendarAppearance, FSCalendarHeaderLayout, FSCalendarCollectionView;
@interface FSCalendarHeaderView : UIView
@ -17,12 +16,10 @@
@property (weak, nonatomic) FSCalendarHeaderLayout *collectionViewLayout;
@property (weak, nonatomic) FSCalendar *calendar;
@property (assign, nonatomic) CGFloat scrollOffset;
@property (assign, nonatomic) UICollectionViewScrollDirection scrollDirection;
@property (assign, nonatomic) BOOL scrollEnabled;
@property (assign, nonatomic) BOOL needsAdjustingViewFrame;
@property (assign, nonatomic) BOOL needsAdjustingMonthPosition;
- (void)setScrollOffset:(CGFloat)scrollOffset;
- (void)setScrollOffset:(CGFloat)scrollOffset animated:(BOOL)animated;
- (void)reloadData;
- (void)configureAppearance;

View File

@ -43,8 +43,6 @@
- (void)initialize
{
_needsAdjustingViewFrame = YES;
_needsAdjustingMonthPosition = YES;
_scrollDirection = UICollectionViewScrollDirectionHorizontal;
_scrollEnabled = YES;
@ -67,34 +65,17 @@
- (void)layoutSubviews
{
[super layoutSubviews];
if (_needsAdjustingViewFrame) {
_needsAdjustingViewFrame = NO;
_collectionViewLayout.itemSize = CGSizeMake(1, 1);
[_collectionViewLayout invalidateLayout];
_collectionView.frame = CGRectMake(0, self.fs_height*0.1, self.fs_width, self.fs_height*0.9);
}
if (_needsAdjustingMonthPosition) {
_needsAdjustingMonthPosition = NO;
[self scrollToOffset:_scrollOffset animated:NO];
}
self.collectionView.frame = CGRectMake(0, self.fs_height*0.1, self.fs_width, self.fs_height*0.9);
}
- (void)dealloc
{
_collectionView.dataSource = nil;
_collectionView.delegate = nil;
self.collectionView.dataSource = nil;
self.collectionView.delegate = nil;
}
#pragma mark - <UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSInteger numberOfSections = self.calendar.collectionView.numberOfSections;
@ -112,11 +93,6 @@
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
[cell setNeedsLayout];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
@ -137,9 +113,6 @@
- (void)setScrollOffset:(CGFloat)scrollOffset animated:(BOOL)animated
{
if (_scrollOffset != scrollOffset) {
_scrollOffset = scrollOffset;
}
[self scrollToOffset:scrollOffset animated:NO];
}
@ -159,7 +132,6 @@
if (_scrollDirection != scrollDirection) {
_scrollDirection = scrollDirection;
_collectionViewLayout.scrollDirection = scrollDirection;
_needsAdjustingMonthPosition = YES;
[self setNeedsLayout];
}
}
@ -251,7 +223,7 @@
- (void)setBounds:(CGRect)bounds
{
[super setBounds:bounds];
_titleLabel.frame = bounds;
self.titleLabel.frame = bounds;
}
- (void)layoutSubviews
@ -273,7 +245,6 @@
CGFloat center = CGRectGetMidY(self.header.bounds);
self.contentView.alpha = 1.0 - (1.0-self.header.calendar.appearance.headerMinimumDissolvedAlpha)*ABS(center-position)/self.fs_height;
}
}
@end
@ -290,10 +261,16 @@
self.minimumLineSpacing = 0;
self.sectionInset = UIEdgeInsetsZero;
self.itemSize = CGSizeMake(1, 1);
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(didReceiveOrientationChangeNotification:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
return self;
}
- (void)dealloc
{
[NSNotificationCenter.defaultCenter removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)prepareLayout
{
[super prepareLayout];
@ -305,6 +282,11 @@
}
- (void)didReceiveOrientationChangeNotification:(NSNotification *)notificatino
{
[self invalidateLayout];
}
- (BOOL)flipsHorizontallyInOppositeLayoutDirection
{
return YES;