ios中两个view动画切换
2013-07-14 19:00 甘超波 阅读(5898) 评论(0) 编辑 收藏 举报@interface ViewController () @property(nonatomic,retain)UIView *redview; @property(nonatomic,retain)UIView *yellowview; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.redview=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; self.redview.backgroundColor=[UIColor redColor]; [self.view addSubview:self.redview]; [self.redview release]; self.yellowview=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; _yellowview.backgroundColor=[UIColor yellowColor]; [self.view addSubview:_yellowview]; //[_yellowview release]; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //转场动画,切换两个view 注意:如果要切换两个viewcontroller做转场要找到共同view; UIView *fromvalue=nil; UIView *tovalue=nil; if(_yellowview.superview){ fromvalue=_yellowview; tovalue=_redview; } else{ fromvalue=_redview; tovalue=_yellowview; } [UIView transitionFromView:fromvalue toView:tovalue duration:0.5 options:UIViewAnimationOptionTransitionFlipFromBottom completion:^(BOOL finished) { //这个api 原理 : // 1:[fromvalue.superview addSubview:tovalue]; // 2:[fromvalue removeFromSuperview]; NSLog(@"fromvalue-->%@",fromvalue.superview); NSLog(@"tovalue-->%@",tovalue.superview); }]; }
目前我正在专注NLP,请立刻加微信/QQ号 546611623, 免费送你原创《NLP高级执行师》高清视频