UIViewAnimationWithBlocks使用block,动画结束后不需要使用回调方法,相比UIViewAnimation 方式要简洁很多
- (void)setSelectedVeg:(id)sender
{
[selectedVegetableIcon setAlpha:0.0];
[UIView animateWithDuration:0.4
animations: ^{
float angle = [self spinnerAngleForVegetable:sender];
[vegetableSpinner setTransform:CGAffineTransformMakeRotation(angle)];
}
completion:^(BOOL finished) {
[selectedVegetableIcon setAlpha:1.0];
}];
}
以上代码来自WWDC2010 iPlant PlantCareViem.m
UIViewAnimation style Animation
- (void)setSelectedVeg:(id)sender
{
[selectedVegetableIcon setAlpha:0.0];
[UIView beginAnimations:@"setSelectedVeg" context:nil];
float angle = [self spinnerAngleForVegetable:sender];
[vegetableSpinner setTransform:CGAffineTransformMakeRotation(angle)];
[UIView setAnimationDuration:0.4];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(done)];
[UIView commitAnimations];
}
-(void)done
{
[selectedVegetableIcon setAlpha:1.0];
}

Leave a comment