UIView* myView; myView =[[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
imageOne =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"psb.jpeg"]];
imageOne.frame =CGRectMake(0, 0, 200, 200);
imageOne.userInteractionEnabled =YES;
imageOne.layer.cornerRadius = imageOne.frame.size.height /2;
[imageOne.layer setMasksToBounds:YES];
imageTwo =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"profile.png"]];
imageTwo.frame =CGRectMake(0, 0, 200, 200);
imageTwo.userInteractionEnabled =YES;
imageTwo.layer.cornerRadius =imageTwo.frame.size.height/2;
[imageTwo.layer setMasksToBounds:YES];
[myView addSubview:imageTwo];
[myView addSubview:imageOne];
UITapGestureRecognizer* tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeImage:)];
tap.numberOfTapsRequired =1;
[imageOne addGestureRecognizer:tap];
UITapGestureRecognizer* tap2 =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeImage:)];
tap2.numberOfTapsRequired =1;
[imageTwo addGestureRecognizer:tap2];
myView.layer.cornerRadius =myView.frame.size.height/2;
[myView.layer setMasksToBounds:YES];
[self.view addSubview:myView];
showOne =YES;-(void)changeImage:(id) sender{
NSLog(@"----------------");
[UIView transitionFromView:(showOne ? imageOne :imageTwo) toView:(showOne ? imageTwo :imageOne) duration:3 options:UIViewAnimationOptionTransitionFlipFromLeft + UIViewAnimationOptionCurveEaseIn completion:
^(BOOL finished) {
showOne =!showOne;
}];
}
CATransition做动画
CATransition *animation =[CATransition animation];
animation.delegate =self;
animation.duration =3;
animation.timingFunction =UIViewAnimationCurveEaseInOut;
animation.type =@"oglFlip";
NSUInteger z =[[myView subviews] indexOfObject:imageOne];
NSUInteger f =[[myView subviews] indexOfObject:imageTwo];
[myView exchangeSubviewAtIndex:z withSubviewAtIndex:f];
[[myView layer]addAnimation:animation forKey:@"animation"];
本文介绍如何使用Objective-C在iOS应用中实现两个圆形头像图片的切换动画效果,并通过手势识别来触发图片的更换。

514

被折叠的 条评论
为什么被折叠?



