//点击图片
- ( void)selectImageView{
CABasicAnimation *boundsAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"];
boundsAnimation.fromValue = [NSValue valueWithCGRect:self.testImageView.bounds];
boundsAnimation.toValue = [NSValue valueWithCGRect:self.view.bounds];
CABasicAnimation *positionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
positionAnimation.fromValue = [NSValue valueWithCGPoint:self.testImageView.center];
positionAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds))];
CATransition *t = [CATransition animation];
t.type = @"flip";
t.subtype = kCATransitionFromRight;
t.duration = 0.25;
CAAnimationGroup *group = [CAAnimationGroup animation];
group.duration = 0.5;
group.animations = [NSArray arrayWithObjects:boundsAnimation, positionAnimation, nil];
group.fillMode = kCAFillModeForwards;
group.removedOnCompletion = NO;
group.delegate = self;
[self.testImageView.layer addAnimation:group forKey:@"zoomIn"];
[self.testImageView.layer addAnimation:t forKey:@"flip"];
}
//返回初始状态
- (void)TurnSelect{
CABasicAnimation *boundsAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"];
boundsAnimation.fromValue = [NSValue valueWithCGRect:self.view.bounds];
boundsAnimation.toValue = [NSValue valueWithCGRect:self.testImageView.bounds];
CABasicAnimation *positionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
positionAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds))];
positionAnimation.toValue = [NSValue valueWithCGPoint:self.testImageView.center];
CATransition *t = [CATransition animation];
t.type = @"flip";
t.subtype = kCATransitionFromLeft;
t.duration = 0.25;
t.removedOnCompletion = YES;
CAAnimationGroup *group = [CAAnimationGroup animation];
group.duration = 0.5;
group.animations = [NSArray arrayWithObjects:positionAnimation, boundsAnimation, nil];
group.delegate = self;
group.fillMode = kCAFillModeForwards;
group.removedOnCompletion = NO;
[self.testImageView.layer addAnimation:group forKey:@"zoomOut"];
[self.testImageView.layer addAnimation:t forKey:@"flip"];
}
- (void)animationDidStart:(CAAnimation *)anim{
[self.testImageView.layer removeAnimationForKey:@"flip"];
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
[self.testImageView.layer removeAnimationForKey:@"flip"];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.testImageView = [[[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds ] autorelease];
self.testImageView.image = [UIImage imageNamed:@"108.jpg"];
self.testImageView.contentMode = UIViewContentModeScaleAspectFit;
self.testImageView.userInteractionEnabled = YES;
[self.view addSubview:self.testImageView];
self.testImageView.frame = CGRectMake(300, 800, 100, 100);
// self.testImageView.center = self.view.center;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectImageView) ] ;
[self.testImageView addGestureRecognizer:tapGesture];
[tapGesture release];
UIButton *testBtn = [[[UIButton alloc]initWithFrame:CGRectMake(700, 700, 100, 100) ] autorelease];
testBtn.backgroundColor = [UIColor greenColor];
[testBtn addTarget:self action:@selector(TurnSelect) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:testBtn];
}