아래와 같이 UICollectionView를 만듭니다. UICollectionViewCell에있는 UIButton에 대한 UIEvent를 차단하고 싶습니다.
내가이 UICollectionView에 대해하고 싶은 것은
,- 각 UICollectionViewCell가있는 UIButton있다 ([cell.contentView addSubview : 버튼])
- 있는 UIButton이 UIControlEventTouchDown 및 UIControlEventTouchUpInside을 처리해야
- UICollectionView 셀을 길게 눌러 대화 형 작업 시작
- 시작하지 마세요. UIButton을 길게 눌러 대화 형 작업. UIButton은 2 단계에서 할당 한 UIControlEvent를 처리합니다.
- UIButton 이외의 UICollectionViewCell 영역을 두드리면 (didSelectItemAtIndexPath :) 처리하고 싶습니다.
내 문제는 UICollectionView에 대한 handleLongPress가 응답과 긴있는 UIButton 도청 경우에도 interactiveMovement을 시작한다는 것입니다.
UIButton 이외의 UICollectionView 영역을 두드리는 경우에만 interactiveMovement를 시작하고 싶습니다.
UIButton을 길게 누르면 UIConEvent가 UIButton에 할당되고 UICollectionView가 응답하지 않게하고 싶습니다.
몇 가지 해결책이 있다면 고맙겠습니다.
내 코드는 아래와 같습니다. 감사합니다.
MyCollectionView : UICollectionView
- (id)init
{
self = [super initWithFrame:CGRectZero collectionViewLayout:[[UICollectionViewFlowLayout alloc] init]];
if (self) {
self.delegate = self;
self.dataSource = self;
--- snip ---
[self addLongPressGesture];
--- snip ---
}
return self;
}
- (void)addLongPressGesture
{
UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(handleLongPress:)];
[self addGestureRecognizer:gesture];
}
- (void)handleLongPress:(UILongPressGestureRecognizer *)sender
{
CGPoint point = [sender locationInView:sender.view];
NSIndexPath *indexPath = [self indexPathForItemAtPoint:point];
switch (sender.state) {
case UIGestureRecognizerStateBegan:
[self beginInteractiveMovementForItemAtIndexPath:indexPath];
break;
case UIGestureRecognizerStateChanged:
[self updateInteractiveMovementTargetPosition:point];
break;
case UIGestureRecognizerStateEnded:
[self endInteractiveMovement];
break;
default:
[self cancelInteractiveMovement];
break;
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
// something to do
}
MyUICollectionViewCell : UICollectionViewCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initButton];
}
return self;
}
- (void)initButton
{
_button = [[UIButton alloc] init];
[_button addTarget:self action:@selector(touchUpButton:) forControlEvents:UIControlEventTouchUpInside];
[_button addTarget:self action:@selector(touchDownButton:) forControlEvents:UIControlEventTouchDown];
--- snip ---
[self addSubview:_button];
}
- (void)touchUpButton:(UIButton *)button
{
// something to do
}
- (void)touchDownButton:(UIButton *)button
{
// something to do
}
코드가 모든 문제를 해결 –
@Sh_Khan 번호를 때 나는 길게 누르면있는 UIButton UICollectionView의 InteractiveMovement를 시작합니다. UICuttonView가 아니라 UIControlViewCell을 길게 누르면 시작할 수 있습니다. 고맙습니다. –