讲述属性动画的使用 —使用动画旋转、平移、渐变和缩放
来源:互联网 发布:雪迪龙网络报销系统 编辑:程序博客网 时间:2024/05/22 17:39
//
// ViewController.h
// Demo
//
// Created by yixia on 15/7/14.
// Copyright (c) 2015年 yixia. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController :UIViewController
@property (weak, nonatomic) IBOutletUITableView *tableView;
@end
//
// ViewController.m
// Demo
//
// Created by yixia on 15/7/14.
// Copyright (c) 2015年 yixia. All rights reserved.
//
#import "ViewController.h"
@interface ViewController () <UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UIView *headView;
@property (nonatomic,strong) UIView *testView;
- (IBAction)change:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.headView = [[UIViewalloc] initWithFrame:CGRectMake(0,0, [UIScreenmainScreen].bounds.size.width,100)];
self.headView.backgroundColor = [UIColorpurpleColor];
self.tableView.tableHeaderView =self.headView;
// UIView *view =self.tableView.tableHeaderView;
// view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200);
// [self.tableView setTableHeaderView:view];
self.testView = [[UIViewalloc] initWithFrame:CGRectMake(20,100, 100, 44)];
self.testView.backgroundColor = [UIColorredColor];
[self.viewaddSubview:self.testView];
[superviewDidLoad];
// 指定图像的位置
//self.testView.center = self.view.center;
}
//#pragma mark - 懒加载
//- (UIImageView *)testView
//{
// if (!_testView) {
// _testView = [[UIImageView alloc] initWithImage:
// [UIImage imageNamed:@"heart"]];
// [self.view addSubview:_testView];
// }
//return _testView;
// }
/** 触摸开始的方法*/
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 获取触摸点
CGPoint point = [[touches anyObject] locationInView:self.view];
// // 实现平移的动画
[selftranslationAnimation:point];
//实现渐变的动画
[selfalphaChangedAnimation];
//实现缩放的动画
[selfscaleAnimation];
//实现旋转的动画
[selfrotateAnimation];
}
/** 平移动画的方法*/
- (void)translationAnimation:(CGPoint)point
{
//创建基本动画,并指定可动画属性
CABasicAnimation *basicAnimation = [CABasicAnimation
animationWithKeyPath:@"position"];
// 设置目标值
basicAnimation.toValue = [NSValuevalueWithCGPoint:point];
//动画播放完成后,停留在目标位置
basicAnimation.removedOnCompletion =NO;
basicAnimation.fillMode =kCAFillModeForwards;
// 设置动画的时间函数
basicAnimation.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseOut];
// 设置动画的时长
basicAnimation.duration =2.0f;
// 添加到iconView的图层
[self.testView.layeraddAnimation:basicAnimation forKey:nil];
}
/** 渐变动画的方法*/
- (void)alphaChangedAnimation
{
//创建一个基本动画,并指定可动画属性
CABasicAnimation *basicAnimation = [CABasicAnimation
animationWithKeyPath:@"opacity"];
// 设置起始值
basicAnimation.fromValue =@1.0;
// 设置目标值
basicAnimation.toValue =@0.0;
// 设置重复次数
basicAnimation.repeatCount =MAXFLOAT;
// 设置动画的时长
basicAnimation.duration =2.0f;
// 添加到iconView的图层
[self.testView.layeraddAnimation:basicAnimation forKey:nil];
}
/** 缩放动画的方法*/
- (void)scaleAnimation
{
//创建一个基本动画,并指定可动画属性
CABasicAnimation *basicAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.scale"];
// 设置初始值和目标值
basicAnimation.fromValue =@1.0;
basicAnimation.toValue =@0.5;
// 设置重复次数
basicAnimation.repeatCount =MAXFLOAT;
// 设置动画的时长
basicAnimation.duration =2.0f;
// 添加到iconView的图层
[self.testView.layeraddAnimation:basicAnimation forKey:nil];
}
/** 旋转动画的方法*/
- (void)rotateAnimation
{
//创建一个基本动画,并指定可动画属性
CABasicAnimation *basicAnimation = [CABasicAnimation
animationWithKeyPath:@"transform.rotation.y"];
// 设置初始值和目标值
basicAnimation.fromValue =@0;
basicAnimation.toValue =@(M_PI);
// 设置动画的时长
basicAnimation.duration =2.0f;
// 添加到的图层
[self.testView.layeraddAnimation:basicAnimation forKey:nil];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"Cell"forIndexPath:indexPath];
cell.textLabel.text = [@"row: "stringByAppendingFormat:@"%@",@(indexPath.row)];
return cell;
}
- (IBAction)change:(id)sender {
NSLog(@"change");
[self.testViewsetBackgroundColor:[UIColoryellowColor]];
CGRect rect = self.testView.frame;
rect.origin.x =100;
rect.size.width =200;
rect.size.height =150;
self.testView.frame =rect;
}
@end
- 讲述属性动画的使用 —使用动画旋转、平移、渐变和缩放
- Android中属性动画1----ObjectAnimator的基本使用(平移,缩放,渐变,旋转)
- 旋转、平移、缩放和透明度渐变的补间动画
- Android中补间动画1----Animation的基本使用代码实现(平移,缩放,渐变,旋转)
- Android 实现属性动画平移,旋转,缩放,渐变 《H》
- 【Android开发】动画范例2-旋转、平移、缩放和透明度渐变的补间动画
- 旋转平移,缩放,透明度渐变的补间动画
- Android 旋转、平移、缩放和透明度渐变的补间动画
- 动画效果之渐变、缩放、平移、旋转<代码实现>
- 动画效果之渐变、缩放、平移、旋转<代码实现>
- Android 补间动画(动画列表,平移,旋转,缩放,渐变,动画集合)
- 组合属性动画:缩放、渐变 平移和旋转+ImageLoader加载图片+MVP+OKhttp+拦截器+请求网络数据二级列表购物车
- 属性动画的平移加旋转
- android动画,旋转,渐变,缩放
- 赵雅智_Tween动画(旋转、平移、放缩和渐变)
- Android动画-旋转、平移、放缩和渐变
- QML图像、状态和动画--缩放、旋转和平移
- css3之元素的缩放、渐变、旋转和平移
- 智能家居带来冲击,墙面开关面临消…
- fread 返回 0的情况
- 文字渐变效果:图层中的mask属性
- 根据ip获取对应地区
- perror 使用
- 讲述属性动画的使用 —使用动画旋转、平移、渐变和缩放
- malloc 分配内存 也是需要占用内存
- vim 快捷键
- ios7 ios8 定位兼容性问题解决方案
- /dev/mem
- C语言的inline
- inline与__inline__的区别
- 实例解说Linux中fdisk分区使用方法
- c语言中字符串中的双引号