#动画设置 UIView动画实现
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *myView;
@property (weak, nonatomic) IBOutlet UIView *redView;
@end #pragma mark - UIView类实现动画 #pragma mark - Animating Views with Block Object
@implementation ViewController
- (IBAction)handleViewOne:(id)sender { /* 方法1:Block语法的动画 */ [UIView animateWithDuration: animations:^{ /* 控件的属性发生改变 */
self.myView.frame = CGRectMake(, , , );
self.myView.backgroundColor = [UIColor greenColor]; }]; /* 方法2 */ [UIView animateWithDuration: animations:^{
/* 动画开始的代码*/
self.myView.frame = CGRectMake(, , , );
self.myView.backgroundColor = [UIColor cyanColor]; } completion:^(BOOL finished) { /* 动画执行后的代码段 */
self.myView.frame = CGRectMake(, , , ); }]; /* 方法3 */
/* options参数:动画相关参数,多个之间用 | 分开*/
[UIView animateWithDuration: delay: options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{ /* 开始动画的View属性值 */
self.myView.frame = CGRectMake(, , , );
self.myView.backgroundColor = [UIColor redColor]; } completion:^(BOOL finished) {
}]; /* 方法4 过渡动画效果 */ [UIView transitionWithView:self.myView duration: options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionRepeat animations:^{ self.myView.frame = CGRectMake(, , , ); } completion:^(BOOL finished) { }]; /* 方法5:从一个View过渡到另一个View */ [UIView transitionFromView:self.myView toView:self.redView duration: options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) { }]; /* 方法6:设置弹簧(Spring)相关参数 */ [UIView animateWithDuration: delay:0.5 usingSpringWithDamping:0.1 initialSpringVelocity: options:UIViewAnimationOptionRepeat animations:^{ /* 开始动画的状态 UIView的属性 */
self.myView.frame = CGRectMake(, , , ); } completion:^(BOOL finished) { /* 结束动画 UIView的属性*/ }]; } #pragma mark - Animating Views
- (IBAction)handleViewTow:(id)sender { /* 1,开始动画*/
[UIView beginAnimations:@"FrameChange" context:nil]; /* 2.动画设置 */ [UIView setAnimationDuration:]; /** 重复的次数*/
[UIView setAnimationRepeatCount:NSIntegerMax]; /* 延迟动画 */ [UIView setAnimationDelay:0.5];
self.myView.frame = CGRectMake(, , , ); /* 3.提交动画 */
[UIView commitAnimations]; }
05-11 17:02
查看更多