【问题标题】:UICollectionViewCell Dragging AnimationUICollectionViewCell 拖动动画
【发布时间】:2014-08-04 21:58:47
【问题描述】:

目前我正在实现这个以动画单元格的移动:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event touchesForView:self.contentView] anyObject];
    CGPoint touchLocation = [touch locationInView:self];

    if (CGRectContainsPoint([UIScreen mainScreen].bounds, touchLocation))
    {
        dragging = YES;
        oldX = touchLocation.x;
        oldY = touchLocation.y;
    }
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event touchesForView:self.contentView] anyObject];
    CGPoint touchLocation = [touch locationInView:self.contentView];

    if (dragging)
    {
        self.frame = CGRectOffset(self.frame, touchLocation.x - oldX, touchLocation.y-oldY);
    }

}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    dragging = NO;
    [UIView animateWithDuration:0.3
                          delay:0.1
         usingSpringWithDamping:0.5
          initialSpringVelocity:1.0
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         self.frame = self.origionalFrame;
                     }
                     completion:^(BOOL finished) {
                     }];
}

我遇到的问题是每当我沿 x 方向移动时,因为我的 uicollectionview 具有水平滚动和分页功能,它会中断我的触摸事件并停止动画,而不会将单元格移回原位。

有没有办法在我的触摸事件动画期间阻止 uicollecitonview 滚动,或者有办法做到这一点,以便在集合视图滚动到新单元格时两者仍然可以工作?

【问题讨论】:

    标签: ios objective-c uicollectionview uicollectionviewcell


    【解决方案1】:

    设置 UICollectionView 的属性 canCancelContentTouches = NO.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 2017-02-28
      相关资源
      最近更新 更多