Permalink
Browse files

Closes #91.

  • Loading branch information...
1 parent 08952c2 commit 8beacaf40cf7edd5f09bbbee68c9620dc20b44b5 @devinross committed Mar 20, 2013
Showing with 39 additions and 53 deletions.
  1. +1 −6 demo/Classes/CalendarMonthViewController.m
  2. +38 −47 src/TapkuLibrary/TKCalendarMonthView.m
@@ -58,12 +58,7 @@ - (NSArray*) calendarMonthView:(TKCalendarMonthView*)monthView marksFromDate:(NS
}
- (void) calendarMonthView:(TKCalendarMonthView*)monthView didSelectDate:(NSDate*)date{
- // CHANGE THE DATE TO YOUR TIMEZONE
- NSDateComponents *info = [date dateComponentsWithTimeZone:monthView.timeZone];
- NSDate *myTimeZoneDay = [NSDate dateWithDateComponents:info];
-
- NSLog(@"Date Selected: %@",myTimeZoneDay);
-
+ NSLog(@"Date Selected: %@",date);
[self.tableView reloadData];
}
- (void) calendarMonthView:(TKCalendarMonthView*)mv monthDidChange:(NSDate*)d animated:(BOOL)animated{
@@ -67,7 +67,7 @@ @interface TKCalendarMonthTiles : UIView {
- (id) initWithMonth:(NSDate*)date marks:(NSArray*)marks startDayOnSunday:(BOOL)sunday timeZone:(NSTimeZone*)timeZone;
- (void) setTarget:(id)target action:(SEL)action;
-- (void) selectDay:(int)day;
+- (void) selectDay:(NSInteger)day;
- (NSDate*) dateSelected;
+ (NSArray*) rangeOfDatesInMonthGrid:(NSDate*)date startOnSunday:(BOOL)sunday timeZone:(NSTimeZone*)timeZone;
@@ -412,7 +412,6 @@ - (void) drawRect:(CGRect)rect {
}
- (void) selectDay:(NSInteger)day{
-
int pre = firstOfPrev < 0 ? 0 : lastOfPrev - firstOfPrev + 1;
int tot = day + pre;
@@ -421,9 +420,11 @@ - (void) selectDay:(NSInteger)day{
selectedDay = day;
selectedPortion = 1;
-
self.currentDay.font = [UIFont boldSystemFontOfSize:dateFontSize];
+
+
+
if(day == today){
self.currentDay.shadowOffset = CGSizeMake(0, -1);
self.dot.shadowOffset = CGSizeMake(0, -1);
@@ -439,33 +440,24 @@ - (void) selectDay:(NSInteger)day{
}
- [self addSubview:self.selectedImageView];
self.currentDay.text = [numberFormatter stringFromNumber:@(day)];
if ([marks count] > 0) {
- if([marks[row * 7 + column] boolValue]){
+ if([marks[row * 7 + column] boolValue])
[self.selectedImageView addSubview:self.dot];
- }else{
+ else
[self.dot removeFromSuperview];
- }
-
- }else{
- [self.dot removeFromSuperview];
- }
+ }else [self.dot removeFromSuperview];
if(column < 0){
column = 6;
row--;
}
-
- CGRect r = self.selectedImageView.frame;
- r.origin.x = (column*46) - 1;
- r.origin.y = (row*44)-1;
- self.selectedImageView.frame = r;
-
-
+
+ self.selectedImageView.frame = CGRectMakeWithSize((column*46)-1, (row*44)-1, self.selectedImageView.frame.size);
+ [self addSubview:self.selectedImageView];
}
@@ -554,10 +546,7 @@ - (void) reactToTouch:(UITouch*)touch down:(BOOL)down{
- CGRect r = self.selectedImageView.frame;
- r.origin.x = (column*46)-1;
- r.origin.y = (row*44)-1;
- self.selectedImageView.frame = r;
+ self.selectedImageView.frame = CGRectMakeWithSize((column*46)-1, (row*44)-1, self.selectedImageView.frame.size);
if(day == selectedDay && selectedPortion == portion) return;
@@ -667,10 +656,15 @@ + (void) initialize{
- (CGRect) _calculatedFrame{
return CGRectMake(0, 0, self.tileBox.bounds.size.width, self.tileBox.bounds.size.height + self.tileBox.frame.origin.y);
}
-
- (CGRect) _calculatedDropShadowFrame{
return CGRectMake(0, self.tileBox.bounds.size.height + self.tileBox.frame.origin.y, self.bounds.size.width, 6);
}
+- (void) _updateSubviewFramesWithTile:(UIView*)tile{
+ self.tileBox.frame = CGRectMakeWithSize(0, TOP_BAR_HEIGHT-1, tile.frame.size);
+ self.frame = CGRectMakeWithPoint(self.frame.origin, self.bounds.size.width, self.tileBox.frame.size.height+self.tileBox.frame.origin.y);
+ self.shadow.frame = self.tileBox.frame;
+ self.dropshadow.frame = [self _calculatedDropShadowFrame];
+}
- (id) initWithSundayAsFirst:(BOOL)s timeZone:(NSTimeZone*)timeZone{
if (!(self = [super initWithFrame:CGRectZero])) return nil;
@@ -788,7 +782,7 @@ - (id) init{
}
- (void) didMoveToWindow{
- if (self.window)
+ if (self.window && currentTile == nil)
[self reloadData];
}
@@ -853,23 +847,15 @@ - (void) changeMonthAnimation:(UIView*)sender{
if(isNext){
-
currentTile.frame = CGRectMake(0, -1 * currentTile.bounds.size.height + overlap + 2, currentTile.frame.size.width, currentTile.frame.size.height);
newTile.frame = CGRectMake(0, 1, newTile.frame.size.width, newTile.frame.size.height);
- self.tileBox.frame = CGRectMakeWithPoint(self.tileBox.frame.origin, self.tileBox.frame.size.width, newTile.frame.size.height);
-
-
}else{
-
newTile.frame = CGRectMake(0, 1, newTile.frame.size.width, newTile.frame.size.height);
- self.tileBox.frame = CGRectMakeWithPoint(self.tileBox.frame.origin, self.tileBox.frame.size.width, newTile.frame.size.height);
currentTile.frame = CGRectMake(0, newTile.frame.size.height - overlap, currentTile.frame.size.width, currentTile.frame.size.height);
-
}
- self.frame = [self _calculatedFrame];
- self.shadow.frame = self.tileBox.frame;
- self.dropshadow.frame = [self _calculatedDropShadowFrame];
+ [self _updateSubviewFramesWithTile:newTile];
+
[UIView commitAnimations];
@@ -929,31 +915,31 @@ - (void) selectDate:(NSDate*)date{
NSArray *dates = [TKCalendarMonthTiles rangeOfDatesInMonthGrid:month startOnSunday:sunday timeZone:self.timeZone];
NSArray *data = [self.dataSource calendarMonthView:self marksFromDate:dates[0] toDate:[dates lastObject]];
- TKCalendarMonthTiles *newTile = [[TKCalendarMonthTiles alloc] initWithMonth:month
- marks:data
- startDayOnSunday:sunday timeZone:self.timeZone];
+ TKCalendarMonthTiles *newTile = [[TKCalendarMonthTiles alloc] initWithMonth:month marks:data startDayOnSunday:sunday timeZone:self.timeZone];
[newTile setTarget:self action:@selector(tile:)];
+
[currentTile removeFromSuperview];
currentTile = newTile;
[self.tileBox addSubview:currentTile];
- self.tileBox.frame = CGRectMakeWithSize(0, TOP_BAR_HEIGHT-1, newTile.frame.size);
- self.frame = CGRectMakeWithPoint(self.frame.origin, self.bounds.size.width, self.tileBox.frame.size.height+self.tileBox.frame.origin.y + 1);
-
- self.shadow.frame = self.tileBox.frame;
-
- self.dropshadow.frame = [self _calculatedDropShadowFrame];
-
+ [self _updateSubviewFramesWithTile:newTile];
self.monthYear.text = [date monthYearStringWithTimeZone:self.timeZone];
- [currentTile selectDay:info.day];
-
+
if([self.delegate respondsToSelector:@selector(calendarMonthView:monthDidChange:animated:)])
[self.delegate calendarMonthView:self monthDidChange:date animated:NO];
+ [newTile selectDay:info.day];
+
+
+
}
}
- (void) reloadData{
+
+ NSDate *d = currentTile.dateSelected;
+ [currentTile removeFromSuperview];
+
NSArray *dates = [TKCalendarMonthTiles rangeOfDatesInMonthGrid:[currentTile monthDate] startOnSunday:sunday timeZone:self.timeZone];
NSArray *ar = [self.dataSource calendarMonthView:self marksFromDate:dates[0] toDate:[dates lastObject]];
@@ -964,8 +950,12 @@ - (void) reloadData{
[currentTile removeFromSuperview];
currentTile = refresh;
+ if(d){
+ NSDateComponents *c = [d dateComponentsWithTimeZone:self.timeZone];
+ [currentTile selectDay:c.day];
+ }
+
}
-
- (void) tile:(NSArray*)ar{
if([ar count] < 2){
@@ -999,6 +989,7 @@ - (void) tile:(NSArray*)ar{
[currentTile selectDay:day];
+
if([self.delegate respondsToSelector:@selector(calendarMonthView:didSelectDate:)])
[self.delegate calendarMonthView:self didSelectDate:dateForMonth];

0 comments on commit 8beacaf

Please sign in to comment.