UIView .
来源:互联网 发布:读远网 知乎 编辑:程序博客网 时间:2024/05/16 08:35
UIView翻转效果实现
新建一个view-based模板工程,在ViewController文件中添加下面的代码,即可实现翻转效果;
- (void)viewDidLoad {
[super viewDidLoad];
//需要翻转的视图
UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, 320, 200)];
parentView.backgroundColor = [UIColor yellowColor];
parentView.tag = 1000;
[self.view addSubview:parentView];
}
//需要在h头文件声明下面的动作响应函数
//在xib文件中添加一个button,其响应函数为下面的函数
//运行程序后,点击button就看到翻转效果
-(IBAction)ActionFanzhuan{
//获取当前画图的设备上下文
CGContextRef context = UIGraphicsGetCurrentContext();
//开始准备动画
[UIView beginAnimati*****:nil context:context];
//设置动画曲线,翻译不准,见苹果官方文档
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//设置动画持续时间
[UIView setAnimationDuration:1.0];
//因为没给viewController类添加成员变量,所以用下面方法得到viewDidLoad添加的子视图
UIView *parentView = [self.view viewWithTag:1000];
//设置动画效果
[UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:parentView cache:YES]; //从上向下
// [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:parentView cache:YES]; //从下向上
// [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:parentView cache:YES]; //从左向右
// [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:parentView cache:YES];//从右向左
//设置动画委托
[UIView setAnimationDelegate:self];
//当动画执行结束,执行animationFinished方法
[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
//提交动画
[UIView commitAnimati*****];
}
//动画效果执行完毕
- (void) animationFinished: (id) sender{
NSLog(@"animationFinished !");
}
运行程序,点击按钮,就能看到动画效果了。
新建一个view-based模板工程,在ViewController文件中添加下面的代码,即可实现翻转效果;
- (void)viewDidLoad {
[super viewDidLoad];
//需要翻转的视图
UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, 320, 200)];
parentView.backgroundColor = [UIColor yellowColor];
parentView.tag = 1000;
[self.view addSubview:parentView];
}
//需要在h头文件声明下面的动作响应函数
//在xib文件中添加一个button,其响应函数为下面的函数
//运行程序后,点击button就看到翻转效果
-(IBAction)ActionFanzhuan{
//获取当前画图的设备上下文
CGContextRef context = UIGraphicsGetCurrentContext();
//开始准备动画
[UIView beginAnimati*****:nil context:context];
//设置动画曲线,翻译不准,见苹果官方文档
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//设置动画持续时间
[UIView setAnimationDuration:1.0];
//因为没给viewController类添加成员变量,所以用下面方法得到viewDidLoad添加的子视图
UIView *parentView = [self.view viewWithTag:1000];
//设置动画效果
[UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:parentView cache:YES]; //从上向下
// [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:parentView cache:YES]; //从下向上
// [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:parentView cache:YES]; //从左向右
// [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:parentView cache:YES];//从右向左
//设置动画委托
[UIView setAnimationDelegate:self];
//当动画执行结束,执行animationFinished方法
[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
//提交动画
[UIView commitAnimati*****];
}
//动画效果执行完毕
- (void) animationFinished: (id) sender{
NSLog(@"animationFinished !");
}
运行程序,点击按钮,就能看到动画效果了。
0 0
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIView
- UIVIew
- UIView
- UIView
- UITextfield
- 我感兴趣的博客和网站2(2015.2.22)
- C++自定义数据类型之结构
- 【JavaScript】JavaScript的对象-构造方法与this关键字
- Msm8960(APQ8064)平台的MSM-AOSP-kitkat编译适配(9):摄像头GPS传感器
- UIView .
- session 之session混乱解决方法
- pat 1090
- 二叉树的深度优先与广度优先遍历
- 解决 Android SDK Manager 不显示老版本API的问题
- HTTP2协议规范详述
- Msm8960(APQ8064)平台的MSM-AOSP-kitkat编译适配(10):其它
- 【JavaScript】JavaScript的对象-在函数中修改参数值的问题
- Windows 下安装 Jekyll