Skip to content

手势动画完成百分比那个地方为什么是除以1800? #2

Description

@xypng

SecondViewController的view上你添加了一个拖动手势,然后用percent记录动画完成百分比,但为什么是除以1800?
percent = yOffset / 1800;
而我改成正确的百分比再更新[percentDrivenInteractiveTransition updateInteractiveTransition:percent];反而不对了,我用NSLog查看百分比明显percent还没有到1的时候动画就已经走完了。

我把手势的方法改成了下面这样:
-(void)panGes:(UIPanGestureRecognizer *)gesture{
CGFloat yOffset = [gesture translationInView:self.view].y;
percent = yOffset / ([UIScreen mainScreen].bounds.size.height-100.0);
percent = MAX(0, MIN(1, percent));
NSLog(@"percent:%f", percent);

if (gesture.state == UIGestureRecognizerStateBegan) {
    percentDrivenInteractiveTransition = [[UIPercentDrivenInteractiveTransition alloc]init];
    //这句必须加上!!
    [self dismissViewControllerAnimated:YES completion:nil];
}else if (gesture.state == UIGestureRecognizerStateChanged){
    [percentDrivenInteractiveTransition updateInteractiveTransition:percent];
}else if (gesture.state == UIGestureRecognizerStateCancelled || gesture.state == UIGestureRecognizerStateEnded){
    [percentDrivenInteractiveTransition finishInteractiveTransition];

// if (percent > 0.06) {
//
//
// }else{

// [percentDrivenInteractiveTransition cancelInteractiveTransition];

// }
//这句也必须加上!!
percentDrivenInteractiveTransition = nil;
}
}

然后我在日志中看到percent还没到1,动画就走完了

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions