UIView动画UIView Animation总结

本文详细介绍了如何使用UIKit中的UIView类实现视图过渡动画效果,包括从一个视图过渡到另一个视图,以及通过添加子视图来实现动画。代码示例展示了如何设置视图属性,如位置、大小和背景颜色,并触发不同类型的过渡动画。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

    UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

    [self.view addSubview:baseView];

    baseView.backgroundColor = [UIColor blueColor];

    baseView.center = self.view.center;

    

    UIView *views = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

    views.backgroundColor = [UIColor greenColor];

    self.views = views;

    [baseView addSubview:views];

    

    UIView *view_1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

    view_1.backgroundColor = [UIColor yellowColor];

    self.view_1 = view_1;

}

 

 

 

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    

 

   

    [UIView transitionFromView:self.views

                        toView:self.view_1

                      duration:2

                       options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {

                       }];

}

1444134-8514c630f8bbef73.gif

UIView *views = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

    views.backgroundColor = [UIColor greenColor];

    self.views = views;

    [self.view addSubview:views];

    views.center = self.view.center;

    

    UIView *view_1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];

    view_1.backgroundColor = [UIColor yellowColor];

    self.view_1 = view_1;

}

 

 

 

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    

   

    [UIView transitionWithView:self.views

                      duration:3

                       options:UIViewAnimationOptionTransitionCurlUp

                    animations:^{

                        [self.views addSubview:self.view_1];

                    } completion:^(BOOL finished) {

                    }];

}

 

1444134-3884cded6d157a53.gif

http://www.cocoachina.com/ios/20170710/19794.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值