gpt4 book ai didi

ios - 在 CollectionView 的 didSelectItemAtIndexPath 方法中获取 CGPoint

转载 作者:可可西里 更新时间:2023-11-01 06:21:39 28 4
gpt4 key购买 nike

有没有办法获取 uicollectionViewCell 中点击点的坐标?如果我单击 Y 坐标 < 50 的矩形,我想执行方法 A,如果 Y > 50,我想执行方法 B。

最佳答案

还有选项 B,子类化 UITableViewCell 并从 UIResponder 类获取位置:

@interface CustomTableViewCell : UITableViewCell

@property (nonatomic) CGPoint clickedLocation;

@end

@implementation CustomTableViewCell

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
self.clickedLocation = [touch locationInView:touch.view];
}

@end

然后从 TableViewCell 中获取它自己的位置:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//get the cell
CustomTableViewCell *cell = (CustomTableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
//get where the user clicked
if (cell.clickedLocation.Y<50) {
//Method A
}
else {
//Method B
}
}

关于ios - 在 CollectionView 的 didSelectItemAtIndexPath 方法中获取 CGPoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26709767/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com