为了添加一个看起来像Passbook-Menu'的菜单。在我的Swift应用程序中,我从Github找到了一个用Objective-C编写的适当的演示。我顺利地将ObjC翻译成Swift,直到我在原始演示中找到两个Block。我知道在我检查了一些指南书后,Block应该被翻译成Closure。
我试过但我失败了。 Complier抛出了" animatedWithDuration()缺少参数' delay' "
非常感谢您的时间和指导。
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){} }) } } ) }
}
答案 0 :(得分:1)
尝试在第一个参数上将duration / 2
替换为NSTimeInterval(duration / 2)
。