[英]iOS Blocks - defining UIView animation-like blocks
我正在嘗試創建一個自定義塊,例如UIView
動畫塊。 基本上,我希望能夠傳遞方法或任意數量的指令,並提供完成處理程序。 我的問題是如何指定塊定義的參數部分?
您可以有一個方法聲明,例如:
- (void) performAnimationWithCompletion:(void (^)(BOOL finished))completion {
[UIView animateWithDuration:0.5 animations:^{
// your own animation code
// ...
} completion:^(BOOL finished) {
// your own completion code
// if completion block defined, call it
if(completion){
completion(YES);
}
}];
}
然后,您可以使用以下命令調用它:
[instance performAnimationWithCompletion:^(BOOL complete){
// define block code to be executed on completion
}];
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
// other animations here
}
completion:^(BOOL finished){
// ... completion stuff
}
];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.