iOS ---如硬币翻转动画

2016-07-05  本文已影响2018人  71150ce14a00

//需要翻转的视图

UIView*parentView = [[UIViewalloc]initWithFrame:CGRectMake(0,150,320,200)];

parentView.backgroundColor= [UIColoryellowColor];

parentView.tag=1000;

[self.viewaddSubview:parentView];

UIButton*button = [[UIButtonalloc]initWithFrame:CGRectMake(100,350,100,100)];

button.backgroundColor= [UIColorredColor];

[buttonaddTarget:selfaction:@selector(ActionFanzhuan)forControlEvents:UIControlEventTouchUpInside];

[self.viewaddSubview:button];

}

-(void)ActionFanzhuan{

//获取当前画图的设备上下文

CGContextRefcontext =UIGraphicsGetCurrentContext();

//开始准备动画

[UIViewbeginAnimations:nilcontext:context];

//设置动画曲线,翻译不准,见苹果官方文档

[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];

//设置动画持续时间

[UIViewsetAnimationDuration:1.0];

//因为没给viewController类添加成员变量,所以用下面方法得到viewDidLoad添加的子视图

UIView*parentView = [self.viewviewWithTag:1000];

//设置动画效果

//    [UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:parentView cache:YES];  //从上向下

// [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:parentView cache:YES];   //从下向上

[UIViewsetAnimationTransition:UIViewAnimationTransitionFlipFromLeftforView:parentViewcache:YES];//从左向右

//     [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:parentView cache:YES];//从右向左

//设置动画委托

[UIViewsetAnimationDelegate:self];

//当动画执行结束,执行animationFinished方法

[UIViewsetAnimationDidStopSelector:@selector(animationFinished:)];

//提交动画

[UIViewcommitAnimations];

}

//动画效果执行完毕

- (void) animationFinished: (id) sender{

NSLog(@"animationFinished !");

}

关注微信公众号:

上一篇 下一篇

猜你喜欢

热点阅读