首页 > 代码库 > 实现多个UIView之间切换的动画效果
实现多个UIView之间切换的动画效果
@interface RootViewController (){ UIView *view1; UIView *view2; int flag;}@end@implementation RootViewController- (void)viewDidLoad{ [super viewDidLoad]; flag = 1; UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(130, 65, 50, 35)]; [button setTitle:@"点击" forState:UIControlStateNormal]; [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal]; [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 100, 320, 480)]; view1.backgroundColor = [UIColor grayColor]; view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 100, 320, 480)]; view2.backgroundColor = [UIColor orangeColor];}- (void)click{ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.6f]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:NO]; if (flag == 1) { [self.view addSubview:view1]; flag = 2; }else if(flag == 2){ [self.view addSubview:view2]; flag = 1; } [UIView commitAnimations];}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。