Gavin.han

致力于移动开发 技术改变生活

导航

视图翻转

Posted on 2012-10-19 22:11  gavin.han  阅读(216)  评论(0编辑  收藏  举报

 

1.新建一个Empty Application程序

修改文件appDelegate.m

在方法- (BOOL)application::添加以下代码:

//视图,hanjun
tview = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
tview.backgroundColor = [UIColor redColor];
[self.window addSubview:tview];

//创建按钮
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// btn.titleLabel = @"翻转";
[btn setTitle:@"翻转" forState:UIControlStateNormal];
btn.frame = CGRectMake(100, 300, 100, 30);
[btn addTarget:self
action:@selector(animateAction:)
forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:btn];

2.//按钮点击产生的事件(方法)

- (void) animateAction:(id)sender
{
//动画部分
//动画块
[UIView beginAnimations:nil context:nil];//动画块的开始
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:tview
cache:YES];
[UIView commitAnimations];//结束动画
}

3.commad+r,运行成功即可!