0

我正在尝试获取 FSCalendarView 中选定单元格的位置。(FSCalendar 库)。虽然我从屏幕获取位置,但它不是一个完美的位置,因为我想从那个日期单元格显示弹出窗口。

我做了这样的事情,以获得触摸位置,

#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
}

这就是我能够从这段代码中实现的,

在此处输入图像描述

但是当我在日期上方触摸 lil 时,我得到了与该触摸相对应的位置,并且弹出窗口没有出现在正确的位置。它看起来像这样,

在此处输入图像描述

有什么方法可以得到正确的日期位置。任何类型的帮助都将是可观的。

4

2 回答 2

1

经过所有可用的方法后找到解决方案FSCalendar

对于有这种需求的人,有一个方法- (CGRect)frameForDate:(NSDate *)date;可以返回选定日期的CGRect,我们可以从这个rec​​t中找到center。

- (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;
}
于 2017-03-20T06:34:53.060 回答
0

看起来您可以使用委托方法 calendar:didSelectDate:atMonthPosition:,然后使用calendar:cellForDate:atMonthPosition:来获取单元格。然后您可以使用 cell.frame 获取位置。

于 2017-03-20T06:06:01.650 回答