我正在寻找一种让动画块排队的方法,并在这个博客文章中看到了:http://xibxor.com/2013/03/27/uiview-animation-without-nested-hell/
我无法让它工作,如何安排这些元素的though...the范围还不清楚。另外,第18、25和32行中的分号是做什么的?有人能解释一下怎么用这个吗?
编辑:下面是从源代码复制的代码:
NSMutableArray* animationBlocks = [NSMutableArray new];
typedef void(^animationBlock)(BOOL);
// getNextAnimation
// removes the first block in the queue and returns it
animationBlock (^getNextAnimation)() = ^{
animationBlock block = animationBlocks.count ? (animationBlock)[animationBlocks objectAtIndex:0] : nil;
if (block){
[animationBlocks removeObjectAtIndex:0];
return block;
}else{
return ^(BOOL finished){};
}
};
//add a block to our queue
[animationBlocks addObject:^(BOOL finished){;
[UIView animateWithDuration:1.0 animations:^{
//...animation code...
} completion: getNextAnimation()];
}];
//add a block to our queue
[animationBlocks addObject:^(BOOL finished){;
[UIView animateWithDuration:1.0 animations:^{
//...animation code...
} completion: getNextAnimation()];
}];
//add a block to our queue
[animationBlocks addObject:^(BOOL finished){;
[UIView animateWithDuration:1.0 animations:^{
//...animation code...
} completion: getNextAnimation()];
}];
//add a block to our queue
[animationBlocks addObject:^(BOOL finished){;
NSLog(@"Multi-step Animation Complete!");
}];
// execute the first block in the queue
getNextAnimation()(YES);发布于 2014-02-19 08:33:58
首先,感谢分享这篇文章,这是一个好主意。这对我来说非常有效:
在你的.h外的@interface
typedef void(^animationBlock)(BOOL);然后在您的.m中(这里是在- (void)viewDidLoad中):
NSMutableArray* animationBlocks = [NSMutableArray new];
UILabel* labelTest = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
labelTest.text = @"Label Test";
[self.view addSubview:labelTest];
// getNextAnimation
// removes the first block in the queue and returns it
animationBlock (^getNextAnimation)() = ^{
animationBlock block = animationBlocks.count ? (animationBlock)[animationBlocks objectAtIndex:0] : nil;
if (block){
[animationBlocks removeObjectAtIndex:0];
return block;
}else{
return ^(BOOL finished){};
}
};
//add a block to our queue
[animationBlocks addObject:^(BOOL finished){;
[UIView animateWithDuration:2.0 animations:^{
NSLog(@"1-step Animation Complete!");
labelTest.alpha = 0;
} completion: getNextAnimation()];
}];
//add a block to our queue
[animationBlocks addObject:^(BOOL finished){;
[UIView animateWithDuration:2.0 animations:^{
labelTest.text = @"New text";
} completion: getNextAnimation()];
}];
//add a block to our queue
[animationBlocks addObject:^(BOOL finished){;
[UIView animateWithDuration:2.0 animations:^{
labelTest.alpha = 1;
} completion: getNextAnimation()];
}];
//add a block to our queue
[animationBlocks addObject:^(BOOL finished){;
NSLog(@"Multi-step Animation Complete!");
}];
// execute the first block in the queue
getNextAnimation()(YES);这是一个非常简单的动画,但是您需要它来测试^^
希望这会有所帮助。
https://stackoverflow.com/questions/21874664
复制相似问题