gpt4 book ai didi

ios - 方法 "animatedWithDuration( )"缺少参数 'delay' 的参数

转载 作者:行者123 更新时间:2023-11-29 02:10:12 25 4
gpt4 key购买 nike

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

我尝试过,但失败了。编译器抛出“animatedWithDuration() 缺少参数‘延迟’的参数”的失败

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

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

伊桑·乔

来源代码:

- (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><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)

关于ios - 方法 "animatedWithDuration( )"缺少参数 'delay' 的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29369332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com