iOS 动画view切换 geekband

//翻页效果(仅适用于转场动画设置,可以从中选择一个进行设置,基本动画、关键帧动画不需要设置)
UIViewAnimationOptionTransitionNone            = 0 << 20, // default没有转场动画效果。
UIViewAnimationOptionTransitionFlipFromLeft    = 1 << 20,//从左侧翻转效果
UIViewAnimationOptionTransitionFlipFromRight   = 2 << 20,//从右侧翻转效果。
UIViewAnimationOptionTransitionCurlUp          = 3 << 20,//向后翻页的动画过渡效果。
UIViewAnimationOptionTransitionCurlDown        = 4 << 20,//向前翻页的动画过渡效果。    
UIViewAnimationOptionTransitionCrossDissolve   = 5 << 20,//旧视图溶解消失显示下一个新视图的效果。
UIViewAnimationOptionTransitionFlipFromTop     = 6 << 20,//从上方翻转效果。 
UIViewAnimationOptionTransitionFlipFromBottom  = 7 << 20,//从底部翻转效果。

案例:

 -(void)run{
if (!_label) {
    _label =[[UILabel alloc]init];
    _label.text = @"From View";
    _label.backgroundColor = [UIColor darkGrayColor];
    [_label sizeToFit];
    _label.center = self.view.center;
}
[self.view  addSubview:_label];
_timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(animate:) userInfo:nil repeats:YES];
 }

-(void)animate:(id)sender{
if ( [_label isDescendantOfView:self.view]){
    [UIView transitionWithView:self.view duration:1.0 options:UIViewAnimationOptionTransitionCurlUp animations:^{
        [_label removeFromSuperview];
    } completion:nil];
}else{
    [UIView transitionWithView:self.view duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        [self.view addSubview:_label];
    }
                    completion:nil];  
}
}

run起来

Snip20160411_19.png

案例

-(void)run6{
if(!_label){
    _label=[[UILabel alloc]init];
    _label.text = @"From View";
    _label.backgroundColor = [UIColor darkGrayColor];
    [_label sizeToFit];
    _label.center =self.view.center;
}
if(!_label2){
    _label2=[[UILabel alloc]init];
    _label2.text = @"To View";
    _label2.backgroundColor = [UIColor darkGrayColor];
    [_label2 sizeToFit];
    _label2.center =self.view.center;
}
[self.view addSubview:_label];

_timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(animation2:) userInfo:nil repeats:YES];

}
-(void)animation2:(id)sender{
if ([_label isDescendantOfView:self.view] ) {
    [UIView transitionFromView:_label toView:_label2 duration:3.0 options:UIViewAnimationOptionTransitionFlipFromBottom completion:nil];
}else{
     [UIView transitionFromView:_label2 toView:_label duration:3.0 options:UIViewAnimationOptionTransitionCrossDissolve completion:nil];
}
}

run起来

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容