【发布时间】:2014-08-18 18:27:38
【问题描述】:
我正在实现类似于 iOS 的内存管理器的东西。这是一个UICollectionView 和UICollectionViewCell 孩子。如果您在单元格上水平滑动,父级将向左平移。但是,如果您垂直滑动,单元格会随着您的手指移动。
在我的 UICollectionViewCell 子类中,我有:
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)];
pan.maximumNumberOfTouches = 1;
pan.minimumNumberOfTouches = 1;
[self addGestureRecognizer:pan];
}
return self;
}
不幸的是,现在所有子单元格都将处理平移手势。父母永远无法处理它们。
- (void)didPan:(UIPanGestureRecognizer *)gesture
{
CGPoint velocity = [gesture velocityInView:self.superview];
if (ABS(velocity.y) > ABS(velocity.x)) {
// Move the cell with the finger
} else {
// Let the parent UICollectionView pan horizontally
}
}
我已经知道如何用手指移动单元格,但我不知道如何做另一种情况:让子单元格忽略平移手势并让其父单元处理它。
【问题讨论】:
-
添加 UISwipeGestureRecognizer 代替平移手势怎么样?
-
@MohdIftekharQurashi 滑动手势在滑动时不提供反馈。那将是糟糕的用户界面。 See article.
标签: ios cocoa-touch event-handling uigesturerecognizer uipangesturerecognizer