//
// Created by WDX on 15/9/23.
// Copyright (c) 2015年 WDongXu. All rights reserved.
//
#import "RootViewController.h"
@interface RootViewController ()
@property (nonatomic, retain)UIView *myView;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addSubViews];
}
// 初始化 创建视图
- (void)addSubViews
{
self.myView = [[UIView alloc]initWithFrame:(CGRectMake(100, 100, 100, 100))];
self.myView.backgroundColor = [UIColor redColor];
[self.view addSubview:self.myView];
[_myView release];
// layer是负责显示图层的
// 要更改 咱们看到的图形的形状 需要更该layer
// 设置圆角
// 先决条件 变圆 必须是长宽相同
self.myView.layer.cornerRadius = self.myView.frame.size.width / 2;
// 设置阴影的颜色
// CGColorRef 图层绘制的颜色
self.myView.layer.shadowColor = [UIColor blackColor].CGColor;
// 显示阴影范围
self.myView.layer.shadowOffset = CGSizeMake(10, 10);
// 阴影透明度
self.myView.layer.shadowOpacity = 1;
// 模糊程度
self.myView.layer.shadowRadius = 50;
// 设置边框
self.myView.layer.borderWidth = 10;
// 设置边框的颜色
self.myView.layer.borderColor = [UIColor blueColor].CGColor;
// layer层动画
// CAKeyframeAnimation抽象类
// CABasicAnimation 基础动画 可以更改大小,旋转等
// CAPropertyAnimation 主要有按照轨迹移动,位置 比如 执行一组动画是使用背景颜色
// 创建一个button
UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
button.frame = CGRectMake(100, 300, 100, 100);
button.backgroundColor = [UIColor blueColor];
[self.view addSubview:button];
[button setTitle:@"点我" forState:(UIControlStateNormal)];
[button addTarget:self action:@selector(actionButton:) forControlEvents:(UIControlEventTouchUpInside)];
}
- (void)actionButton:(UIButton *)button
{
// [self xyAnimation];
//[self sizeAnimation];
//[self changeBackgroundColor];
// [self positionPoint];
[self huangDongPoint];
[self transform3D];
// [self groupAnimation];
}
// 实现晃动
- (void)huangDongPoint
{
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];
CGFloat center = self.myView.layer.position.x;
CGFloat left = center - 10;
CGFloat right = center + 10;
NSNumber *l = [NSNumber numberWithFloat:left];
NSNumber *c = [NSNumber numberWithFloat:center];
NSNumber *r = [NSNumber numberWithFloat:right];
animation.values = @[l,c,r,l,c,r,l,c,r,l,c,r,l,c,r,l,c,r,l,c,r,l,c,r,l,c,r,l,c,r,l,c];
animation.duration = 1;
[self.myView.layer addAnimation:animation forKey:@"huangDong.x"];
}
// 3d旋转
- (void)transform3D
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
// 结束值
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DRotate(self.myView.layer.transform, M_PI, 10, 10, 10)];
// 设置时间
animation.duration = 2;
[self.myView.layer addAnimation:animation forKey:@"transform"];
}