参数'delay'的方法“animatedWithDuration()”缺少参数

时间:2015-03-31 13:01:55

标签: ios animation closures

为了添加一个看起来像Passbook-Menu'的菜单。在我的Swift应用程序中,我从Github找到了一个用Objective-C编写的适当的演示。我顺利地将ObjC翻译成Swift,直到我在原始演示中找到两个Block。我知道在我检查了一些指南书后,Block应该被翻译成Closure。

我试过但我失败了。 Complier抛出了" animatedWithDuration()缺少参数' delay' "

  1. 首先,我需要声明我没有选择animatedWithDuration()具有参数' delay'。
  2. 的方法。
  3. 我不太明白两句被许多惊叹号标记的句子。 "如果(中途)中途(完成)"和#34;如果(完成)完成(完成)"因为' if'句子总是只写一个'()'而不是两个。
  4. 请告诉我我的代码在哪里写错了。
  5. 非常感谢您的时间和指导。

    Ethan Joe

    原始代码:

    - (void)flipTransitionWithOptions:(UIViewAnimationOptions)options halfway_1:(void (^)(BOOL finished))halfway completion:(void (^)(BOOL finished))completion
    {
        CGFloat degree = (options & UIViewAnimationOptionTransitionFlipFromRight) ? -M_PI_2 : M_PI_2;

    CGFloat duration = 0.4;
    CGFloat distanceZ = 2000;
    CGFloat translationZ = self.frame.size.width / 2;
    CGFloat scaleXY = (distanceZ - translationZ) / distanceZ;
    
    CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
    rotationAndPerspectiveTransform.m34 = 1.0 / -distanceZ; // perspective
    rotationAndPerspectiveTransform = CATransform3DTranslate(rotationAndPerspectiveTransform, 0, 0, translationZ);
    
    rotationAndPerspectiveTransform = CATransform3DScale(rotationAndPerspectiveTransform, scaleXY, scaleXY, 1.0);
    self.layer.transform = rotationAndPerspectiveTransform;
    
    [UIView animateWithDuration:duration / 2 animations:^{
        self.layer.transform = CATransform3DRotate(rotationAndPerspectiveTransform, degree, 0.0f, 1.0f, 0.0f);
    } completion:^(BOOL finished){
        if (halfway) halfway(finished); !!!!!!!!!!!!!!!!!!!
        self.layer.transform = CATransform3DRotate(rotationAndPerspectiveTransform, -degree, 0.0f, 1.0f, 0.0f);
        [UIView animateWithDuration:duration / 2 animations:^{
            self.layer.transform = rotationAndPerspectiveTransform;
        } completion:^(BOOL finished){
            self.layer.transform = CATransform3DIdentity;
            if (completion) completion(finished); !!!!!!!!!!!!!!!!
        }];
    }];
    

    My copy-translated version:

    UIView.animateWithDuration(duration / 2, animations: {self.layer.transform = CATransform3DRotate(rotationAndPerspectiveTrabsform, degree, 0.0, 1.0, 0.0)}, completion: {(finshed) -> Void in if halfway(finished) { self.layer.transform = CATransform3DRotate(rotationAndPerspectiveTrabsform, -degree, 0.0, 1.0, 0.0) UIView.animateWithDuration(duration / 2, animations: {self.layer.transform = rotationAndPerspectiveTrabsform}, completion: {(finished) -> Void in self.layer.transform = CATransform3DIdentity if completion(finshed){} }) } } ) }

    }

1 个答案:

答案 0 :(得分:1)

尝试在第一个参数上将duration / 2替换为NSTimeInterval(duration / 2)