2017-03-20 18 views
0

我想在FSCalendarView中獲取選定單元格的位置。 (FSCalendar庫)。雖然我從屏幕上獲取位置,但它不是一個完美的位置,因爲我想顯示從該日期單元格彈出。我想在FSCalendarVIew中選定DateCell的位置。我可以如何獲取?

我做了這樣的事情,讓觸摸位置,

#pragma mark - View Lifecycle 
- (void)viewDidLoad { 
[super viewDidLoad]; 
UITapGestureRecognizer *tapGesture = 
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerTwoTaps)]; 
tapGesture.delegate=self; 
// Set required taps and number of touches 
[tapGesture setNumberOfTapsRequired:1]; 
[tapGesture setNumberOfTouchesRequired:1]; 
[[self view] addGestureRecognizer:tapGesture]; 
} 

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { 
CGPoint pointOnScreen = [touch locationInView:nil]; 
NSLog(@"Point - %f, %f", pointOnScreen.x, pointOnScreen.y); 
NSLog(@"Touch"); 
touchFrame = CGRectMake(pointOnScreen.x, pointOnScreen.y-120, 0, 0); 
return NO; // handle the touch 
} 

這是我能夠從這個塊的代碼實現,

enter image description here

但是,當我觸摸比爾位於日期之後,我得到與該觸摸相對應的位置,並彈出沒有進入正確的位置。它看起來像這樣,

enter image description here

有什麼方法來獲取最新的正確位置。任何類型的幫助都是可觀的。

回答

0

看起來您可以使用代理方法 calendar:didSelectDate:atMonthPosition:然後使用calendar:cellForDate:atMonthPosition:來獲取單元格。然後你可以通過cell.frame獲取位置。通過供FSCalendar

所有方法對於那些誰都會配備這樣的要求, 會後

1

找到解決方案有一個方法- (CGRect)frameForDate:(NSDate *)date;返回選定日期的CGRect,從這個矩形,我們可以發現中心。

- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date { 
touchFrame = [calendarView frameForDate:date]; 
CGPoint mypoint = CGPointMake(touchFrame.origin.x + (touchFrame.size.width/2), touchFrame.origin.y + (touchFrame.size.height/2)); 

touchFrame.origin = mypoint; 
touchFrame.origin.y = touchFrame.origin.y - 120; 
touchFrame.size.height = 0; 
touchFrame.size.width = 0; 
} 
相關問題