ios 開發中,一些經常使用的簡單的動畫能夠用 uivew 自帶的動畫來是實現ios
今天就學習下 UIVIew 一些經常使用的動畫數組
1.學習
// 翻轉的動畫 [UIView beginAnimations:@"doflip" context:nil]; //設置時常 [UIView setAnimationDuration:1]; //設置動畫淡入淡出 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //設置代理 [UIView setAnimationDelegate:self]; //設置翻轉方向 [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.redView cache:YES]; //動畫結束 [UIView commitAnimations];
效果:動畫
2. 位移動畫ui
[UIView beginAnimations:@"move" context:nil]; [UIView setAnimationDuration:2]; [UIView setAnimationDelegate:self]; //改變它的frame的x,y的值 self.redView.frame=CGRectMake(100,100, 120,100); [UIView commitAnimations];
效果:spa
另外一種寫法:代理
[UIView animateWithDuration:0.5 delay:0.1 usingSpringWithDamping:0.5 initialSpringVelocity:5.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ CGPoint point = _redView.center; point.y += 150; [_redView setCenter:point]; } completion:^(BOOL finished) { }];
效果:code
3.關鍵幀動畫blog
void (^keyFrameBlock)() = ^(){ // 建立顏色數組 NSArray *arrayColors = @[[UIColor orangeColor], [UIColor yellowColor], [UIColor greenColor], [UIColor blueColor], [UIColor purpleColor], [UIColor redColor]]; NSUInteger colorCount = [arrayColors count]; // 循環添加關鍵幀 for (NSUInteger i = 0; i < colorCount; i++) { [UIView addKeyframeWithRelativeStartTime:i / (CGFloat)colorCount relativeDuration:1 / (CGFloat)colorCount animations:^{ [_redView setBackgroundColor:arrayColors[i]]; }]; } }; [UIView animateKeyframesWithDuration:5.0 delay:0.0 options:UIViewKeyframeAnimationOptionCalculationModeCubic | UIViewAnimationOptionCurveLinear animations:keyFrameBlock completion:^(BOOL finished) { // 動畫完成後執行 // code... }];
效果:ip