//
// ViewController.m
// UI_23_动画
//
//
// Copyright © 2015年 lirui. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIView *opeView1;
@property (strong, nonatomic) IBOutlet UIView *opeView2;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
#pragma mark 开始动画按钮
- (IBAction)startAnimationButtonDidClicked:(id)sender {
#pragma mark 动画一
//开始动画
[UIView beginAnimations:nil context:nil];
//动画时间
[UIView setAnimationDuration:3.0f];
//重复次数
[UIView setAnimationRepeatCount:5];
//设置UIView 动画自动翻转(返回动画)
[UIView setAnimationRepeatAutoreverses:YES];
//过渡效果
self.opeView1.backgroundColor = [UIColor blackColor];
self.opeView1.frame = CGRectMake(200, 500, self.opeView1.frame.size.width, self.opeView1.frame.size.height);
self.opeView1.center = CGPointMake(200, 590);
//提交动画
[UIView commitAnimations];
#pragma mark UIView 动画二 block形式
[UIView animateWithDuration:3 animations:^{
[UIView setAnimationRepeatCount:3];
[UIView setAnimationRepeatAutoreverses:YES];
self.opeView1.center = CGPointMake(280, 580);
self.opeView2.center = CGPointMake(60, 580);
self.opeView1.transform = CGAffineTransformRotate(self.opeView1.transform, M_2_PI);
self.opeView1.transform = CGAffineTransformScale(self.opeView1.transform, 2, 2);
}];
#pragma mark 动画三:block里面可以嵌套 动画
[UIView animateWithDuration:3 animations:^{
//设置动画的速度曲线
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.opeView1.center = CGPointMake(280, 580);
} completion:^(BOOL finished) {
[UIView animateWithDuration:3 animations:^{
self.opeView1.center = CGPointMake(90, 100);
}];
}];
#pragma mark 动画四
[UIView beginAnimations:nil context:nil];
//设置动画代理
[UIView setAnimationDelegate:self];
//指定动画开始的方法
[UIView setAnimationWillStartSelector:@selector(opeView1StartAnimating)];
//指定动画结束的方法
[UIView setAnimationDidStopSelector:@selector(opeView1DidStopAnimating)];
//设置动画时间
[UIView setAnimationDuration:3];
self.opeView1.backgroundColor = [UIColor yellowColor];
[UIView commitAnimations];
#pragma mark 动画五
[UIView transitionFromView:self.opeView1 toView:self.opeView2 duration:3 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
// 以上5种类型动画都属于UIView动画,都能真正改变UIView的属性
}
-(void)opeView1StartAnimating{
}
-(void)opeView1DidStopAnimating{
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
iOS 动画 UIView动画
最新推荐文章于 2022-02-27 19:35:32 发布