//
// ViewController.m
// 车晓迪demo
//
// Created by Mac on 16/1/11.
// Copyright © 2016年 Mac. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *
circleView;
@end
@implementation ViewController
- (
void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 添加三个扇形按钮
for (
int i =
0; i<
3; i ++
) {
NSString *imgName = [NSString stringWithFormat:
@"circle%d",i +
1];
UIButton *btn =
[UIButton buttonWithType:UIButtonTypeCustom ];
UIImage *img =
[UIImage imageNamed:imgName];
[btn setBackgroundImage:img forState:UIControlStateNormal];
// 因为给定按钮图片的frame已经和背景图片的尺寸是对应好的,此处需要注意一下
btn.frame =
self.circleView.bounds;
[self.circleView addSubview:btn];
}
// 向背景中添加中心按钮
UIButton *centerBtn =
[UIButton buttonWithType:UIButtonTypeCustom];
[centerBtn setBackgroundImage:[UIImage imageNamed:@"home_btn_dealer_had_bind"] forState:UIControlStateNormal];
// 添加进去
[self.view addSubview:centerBtn];
centerBtn.bounds = CGRectMake(
0,
0,
112,
112);
centerBtn.center =
self.circleView.center;
[centerBtn addTarget:self action:@selector(centerBtnClick:) forControlEvents:(UIControlEventTouchUpInside)];
}
- (
void)centerBtnClick:(UIButton *
)centerBtn
{
CGFloat currentAlpha =
self.circleView.alpha;
if (currentAlpha ==
1) {
self.circleView.alpha =
0;
}else{
self.circleView.alpha =
1;
}
// 创建组动画
CAAnimationGroup *groupAni =
[CAAnimationGroup animation];
// 创建核心动画
// 隐藏动画
CABasicAnimation *opacityAni =
[CABasicAnimation animation];
opacityAni.keyPath =
@"opacity";
// 缩放动画
CAKeyframeAnimation *scaleAni =
[CAKeyframeAnimation animation];
scaleAni.keyPath =
@"transform.scale";
// 旋转动画
CABasicAnimation *rotationAni =
[CABasicAnimation animation];
rotationAni.keyPath =
@"transform.rotation";
if (currentAlpha ==
1) {
// 需要隐藏
opacityAni.fromValue = @
1;
opacityAni.toValue = @
0;
scaleAni.values = @[@
1,@
1.2,@
0];
rotationAni.fromValue =@[@
0];
rotationAni.toValue =
@[@(M_PI_4)];
}else{
// 需要显示
opacityAni.fromValue = @
0;
opacityAni.toValue = @
1;
scaleAni.values = @[@
0,@
1.2,@
1];
rotationAni.fromValue =
@[@(M_PI_4)];
rotationAni.toValue = @[@
0];
}
groupAni.animations =
@[opacityAni,scaleAni,rotationAni];
groupAni.duration =
2;
[self.circleView.layer addAnimation:groupAni forKey:nil];
}
@end
转载于:https://www.cnblogs.com/BJTUzhengli/p/5122449.html