声明属性
@property (nonatomic,strong) UIView *cicleView;
构建界面
- (void)transform3dAnimation{
CGFloat width = self.view.bounds.size.width-100;
_cicleView = [[UIView alloc]initWithFrame:CGRectMake(50, 80, width, width)];
[self.view addSubview:_cicleView];
_cicleView.clipsToBounds = YES;
_cicleView.layer.cornerRadius = width/2;
UIColor *color = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];
_cicleView.backgroundColor = [color colorWithAlphaComponent:1.0 ];
UILabel *lab = [[UILabel alloc]init];
lab.frame = CGRectMake((width-width/2)/2, (width-30)/2, width/2, 30);
lab.font = [UIFont systemFontOfSize:30];
lab.textAlignment = NSTextAlignmentCenter;
lab.text = @"30000步";
[_cicleView addSubview:lab];
UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(40, CGRectGetMaxY(_cicleView.frame)+30, 300, 30)];
[self.view addSubview:slider];
[slider addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];
}
添加动画
- (void)changeValue:(UISlider *)slider{
CATransform3D t3d = CATransform3DIdentity;
t3d = CATransform3DRotate(t3d, slider.value*M_PI_2, 1, 0, 0);
t3d = CATransform3DScale(t3d, slider.value*0.15+1, 1, 1);
_cicleView.layer.transform = t3d;
_cicleView.alpha = 1-slider.value;
}