创建一个手势操作
UITapGestureRecognizer点击手势
UILongPressGestureRecognizer长按手势
UISwipeGestureRecognizer滑动手势
UIPinchGestureRecognizer按捏手势
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(添加事件)];
tapGesture.numberOfTapsRequired = 1;//需要点一下响应
tapGesture.numberOfTouchesRequired = 1;//需要一根手指
[self addGestureRecognizer:tapGesture];
// 添加滑动手势
UISwipeGestureRecognizer *swipeG = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(gesture:)];
swipeG.direction = UISwipeGestureRecognizerDirectionRight;
swipeG.delegate = self;
[_redView addGestureRecognizer:swipeG];
//添加手捏手势
UIPinchGestureRecognizer *pinchG = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(gesture:)];
pinchG.scale = 20;
[_redView addGestureRecognizer:pinchG];
//添加旋转手势
UIRotationGestureRecognizer *rotationG = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];
[_redView addGestureRecognizer:rotationG];
//旋转
-(void)rotation:(UIRotationGestureRecognizer *)gesture{
_redView.transform = CGAffineTransformRotate(_redView.transform, gesture.rotation);
}
//放大动画
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = @1;
if (type == kAnimationTypeInner) {
scaleAnimation.toValue = @3;
}else{
scaleAnimation.toValue = @2;
}
//透明动画
CABasicAnimation *opacityAniamtion = [CABasicAnimation animationWithKeyPath:@"opacity"];
opacityAniamtion.fromValue = @1;
opacityAniamtion.toValue = @0;
//组动画,两个动画同时执行
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = @[scaleAnimation,opacityAniamtion];
group.duration = 0.5;
group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
return group;