属性
//view1
@property (nonatomic, strong)UIView *view1;
//view2
@property (nonatomic, strong)UIView *view2;
//view3 作为容器, 将view1和view2添加到view3中
@property (nonatomic, strong)UIView *view3;
伪代码
_view3 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 100)];
[self.view addSubview:view3];
view1.frame = CGRectMake(0, 0, 200, 100);
view2.frame = CGRectMake(0, 0, 200, 100);
[self.view3 addSubview:view1];
[self.view3 addSubview:view2];
// 添加手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
[self.view3 addGestureRecognizer:tap];
- (void)tapClick:(UITapGestureRecognizer *)tap{
if (i % 2 != 0) {
[UIView transitionFromView:self.view1 toView:self.view2 duration:1.0 options:UIViewAnimationOptionTransitionFlipFromTop completion:nil];
}else{
[UIView transitionFromView:self.view2 toView:self.view1 duration:1.0 options:UIViewAnimationOptionTransitionFlipFromBottom completion:nil];
}
i++;
}
动画的关键在于options
, 上面采用的是UIViewAnimationOptionTransitionFlipFromTop
和UIViewAnimationOptionTransitionFlipFromBottom
-
如果我们采用
transitionGif1.gifUIViewAnimationOptionTransitionFlipFromLeft
和UIViewAnimationOptionTransitionFlipFromRight
-
transitionGif2.gifUIViewAnimationOptionTransitionCurlUp
和UIViewAnimationOptionTransitionCurlDown
-
transitionGif3.gifUIViewAnimationOptionTransitionCrossDissolve
网友评论