方法 "animatedWithDuration( )" 缺少参数 'delay' 的自变量

Method "animatedWithDuration( )" missing argument for parameter 'delay'

为了在我的 Swift 应用程序中添加一个看起来像 'Passbook-Menu' 的菜单,我从 Github 中找到了一个用 Objective-C 编写的合适的演示。并且我顺利地将ObjC翻译成了Swift,直到在origin demo中发现了两个Blocks。看了一些指导书才知道Block应该翻译成Closure

我尝试过但失败了。编译器抛出了 "animatedWithDuration( ) missing argument for parameter 'delay' "

的失败
  1. 首先声明一下,我没有select animatedWithDuration() 有参数'delay'.
  2. 的方法
  3. 我不太明白两个带有许多感叹号的句子。 "if (halfway) halfway(finished)" 和 "if (completion) completion(finished)" 因为 'if' 语句总是只写一个 '()',而不是两个。
  4. 请告诉我我的代码哪里写错了。

非常感谢您的宝贵时间和指导。

伊桑·乔

来源代码:

- (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); !!!!!!!!!!!!!!!!
    }];
}];

</p> <p><strong>My copy-translated version:</strong></p> 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){} }) } } ) }

}

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