gpt4 book ai didi

ios - 是否可以将现有方法传递给定义类似于 UIView.animateWithDuration 的回调?

转载 作者:行者123 更新时间:2023-11-28 22:27:09 25 4
gpt4 key购买 nike

该方法最多接受两个回调,animationscomplete。如果我在类方法中定义需要做什么,如何将它们传递给 animateWithDuration

来自: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/clm/UIView/animateWithDuration:animations :

签名看起来像

+ (void)animateWithDuration:(NSTimeInterval)duration 动画:(void (^)(void))animations

通常看起来像这样:

[UIView animateWithDuration:0.2f
delay:0.0f
options:UIViewAnimationOptionCurveEaseIn
animations:^{
_someView.frame = CGRectMake(-150, -200, 460, 650);
_someView.alpha = 0.0;
}
completion:^(BOOL finished) {
}];

所以我正在寻找的是将动画分配给我类(class)中的某个方法。

这个方法被选为一个众所周知的例子。然而,根本原因是我有自己的类尝试执行相同的方法,我想知道是否可以通过不在回调中调用类方法来保持代码更简洁。

我最不喜欢的是 NSError ** 参数,我将其用于我的回调,该参数在出现错误时调用。子调用需要某种全局变量,我真的不喜欢那样。所以这里是我的完整性签名:

- (void)registerWithEmail:(NSString *)email
name:(NSString *)name
willRegister:(void (^)(void))willRegister
didRegister:(void (^)(void))didRegister
registerError:(void (^)(NSError**))registerError;

最佳答案

只需从 block 中调用该方法即可。

    [UIView animateWithDuration:0.4
animations:^{
[self yourMethod];
//...or
[YourClass yourMethod]; // as you said 'class' methods
}
completion:^(BOOL finished) {
[self yourCompletion];
}];

关于ios - 是否可以将现有方法传递给定义类似于 UIView.animateWithDuration 的回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18599791/

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