iOS7 App Manager에서 UICollectionView "스 와이프"
-
21-12-2019 - |
문제
2014 년 이상 iPhone 또는 iPad에서 홈 버튼을 두 번 클릭하여 "App Manager"
를 확인하십시오.
이것은 왼쪽 오른쪽 UICollectionView이지만 "스 와이프 멀리"제스처가 있습니다. 스 와이프.어떻게 끝나나요?UICollectionView에서 셀을 "제거"하는 것은 쉽지 않습니다.
각주 googlers. "필링 끄기", "찢어지는", 컬렉션보기에서 하나의 셀, 여기에 전체 깔끔한 설명 : Https://stackoverflow.com/a/24339705/294884 누군가를 돕기를 바랍니다.
해결책
질문에 대한 의견보다 훨씬 간단 할 수 있습니다.
셀에는 뷰를 포함해야합니다 (드래그 할 것인가)을 포함해야하며 해당보기에 UIPangeStureRecognizer를 추가합니다.
제스처의 조치 방법에서는 뷰를 위아래로 움직이고 삭제하려는 경우 멀리 떨어져 있으면 쉽게 애니메이션을 해제 할 수 있습니다. 여기 에이 부분을 다루는 데 많은 질문이 있습니다.
이렇게하면 컬렉션에 틈새가 나고 이제는 물건을 움직여야합니다. 이것은 꽤 간단합니다.
[_collectionView performBatchUpdates:^{
[_collectionView deleteItemsAtIndexPaths:@[indexPath]];
} completion:^(BOOL finished) {
// you might want to remove the data from the data source here so the view doesn't come back to life when the collection view is reloaded.
}];
.
제거 된 셀 슬라이드의 오른쪽에있는 물건은 모두 좋습니다.
다른 문제점 : 제스처 인식기와 컬렉션 뷰가 함께 즐겁게 연주하는지 확인하십시오. 고맙게도, 그건 너무 까다로운 것은 아닙니다.
[_collectionView.panGestureRecognizer requireGestureRecognizerToFail:pgr]; //where pgr is the recognizer you made for dragging the view off
.
콜렉션 뷰의 팬 제스처가 그 일을 할 수 있도록하기 위해서는 하나의 실패해야합니다. 따라서 위아래로 패닝 할 때만 작동 할 수 있도록 설정하고 컬렉션보기가 왼쪽에서 오른쪽으로 왼쪽으로 왼쪽으로 할 수 있도록하십시오. 제스처 인식 자의 대리자에서 X 축 또는 Y 축에서 더 많이 움직이는지 간단히 검사하는 다음 방법을 구현하십시오.
-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer
{
CGPoint translation =[gestureRecognizer translationInView:self.view];
return(translation.x * translation.x > translation.y * translation.y);
}
. 다른 팁
이 기능을 찾고 있었고 @mbehan 제안을 사용하여 UICollectionView를 사용 하여이 기능을 위조했습니다.
내가 한 일은 컬렉션 셀 (투명한 배경)에 더 작은 크기를 첨가하고 콜렉션 뷰에 단일 팬 제스처를 추가 한 다음 팬 제스처에서 뷰를 움직이고 셀처럼 보입니다.움직이고있다.뷰가 좀 지점에 도달하면 먼저 숨기고 컬렉션보기 셀을 삭제합니다.
셀 계층 구조 : CollectionViewCell ->보기 (태그 값== 2) -> uilabel (태그 값== 1) 레이블은 자리 표시자를 위해 사용됩니다.
아래 코드를 게시하고 있습니다 :
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = (UICollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"Cards" forIndexPath:indexPath];
UILabel *lblNumber = (UILabel*)[cell.contentView viewWithTag:1];
UIView *viewTouch = (UIView*)[cell.contentView viewWithTag:2];
[viewTouch setHidden:NO];
[lblNumber setText:arrCards[indexPath.row]];
return cell;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(0, 50, 0, 30);
}
-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer
{
if([gestureRecognizer isEqual:panGesture]) {
CGPoint point = [(UIPanGestureRecognizer*)gestureRecognizer translationInView:collectionView_];
if(point.x != 0) { //adjust this condition if you want some leniency on the X axis
//The translation was on the X axis, i.e. right/left,
//so this gesture recognizer shouldn't do anything about it
return NO;
}
}
return YES;
}
- (IBAction)panGestureCalled:(UIPanGestureRecognizer *)sender {
yFromCenter = [sender translationInView:collectionView_].y; //%%% positive for up, negative for down
UIView *view = sender.view;
CGPoint location = [view.superview convertPoint:view.center toView:collectionView_];
NSIndexPath *indexPath = [collectionView_ indexPathForItemAtPoint:location];
UICollectionViewCell *cell = [collectionView_ cellForItemAtIndexPath:indexPath];
UIView *touchView = (UIView*)[cell.contentView viewWithTag:2];
switch (sender.state) {
case UIGestureRecognizerStateBegan:{
originalPoint = touchView.center;
break;
};
case UIGestureRecognizerStateChanged:{
touchView.center = CGPointMake(originalPoint.x , originalPoint.y + yFromCenter);
break;
};
//%%% let go of the card
case UIGestureRecognizerStateEnded: {
CGFloat velocityY = (0.2*[(UIPanGestureRecognizer*)sender velocityInView:collectionView_].y);
if (velocityY < -30 && yFromCenter<0) {
[self hideView:touchView withDuration:0.2 andIndexPath:indexPath];
}else if ((yFromCenter< 0 && yFromCenter > -200) || yFromCenter > 0){
CGFloat animationDuration = (ABS(velocityY)*.0002)+.2;
[self resettleViewToOriginalPosition:touchView andDuration:animationDuration];
}else
[self hideView:touchView withDuration:0.2 andIndexPath:indexPath];
};
break;
case UIGestureRecognizerStatePossible:break;
case UIGestureRecognizerStateCancelled:break;
case UIGestureRecognizerStateFailed:break;
}
}
-(void)resettleViewToOriginalPosition:(UIView*)view andDuration:(float)duration{
[UIView animateWithDuration:duration
delay:0.0f
options: UIViewAnimationOptionCurveEaseOut
animations:^
{
[view setCenter:originalPoint];
}
completion:^(BOOL finished)
{
}];
}
- (void)hideView:(UIView*)view withDuration:(float)duration andIndexPath:(NSIndexPath*)indexPath
{
[UIView animateWithDuration:duration
delay:0.0f
options: UIViewAnimationOptionCurveEaseOut
animations:^
{
CGRect frame = view.frame;
frame.origin.y = -300;
view.frame = frame;
}
completion:^(BOOL finished)
{
[view setHidden:YES];
CGRect frame = view.frame;
frame.origin.y = 39;
view.frame = frame;
NSLog(@"View is hidden.");
[arrCards removeObjectAtIndex:indexPath.row];
[collectionView_ performBatchUpdates:^{
[collectionView_ deleteItemsAtIndexPaths:@[indexPath]];
} completion:^(BOOL finished) {
// you might want to remove the data from the data source here so the view doesn't come back to life when the collection view is reloaded.
}];
}];
}
.
콜렉션 뷰의 PagingEnabled를 NO로 보관하고, 가야합니다.