UIView 之 Animation 一边上跳 一边旋转

本文介绍如何使用UIView实现iOS应用中的基本视图动画效果,包括让视图上下跳动及旋转动画。通过设置动画曲线、持续时间等属性,实现流畅且可重复的动画体验。

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

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

view.backgroundColor = [UIColor redColor];

[self.view addSubview:view];

    

上跳:

[UIView beginAnimations:@""context:nil];

[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

[UIView setAnimationDuration:0.7f];

[UIView setAnimationRepeatCount:30];

CGPoint center = view.center;

if (center.y >40.f) {

    center.y -=20;

    view.center = center;

}else{

    center.y +=20;

    view.center = center;

}

[UIView commitAnimations];

    

旋转:

for(int i =0; i <100; i++){

    [UIView beginAnimations:@"rotate"context:nil];

    [UIView setAnimationDuration:10];

    view.transform=CGAffineTransformMakeRotation((i+1)*2.0*M_PI/11.0);

    [UIView commitAnimations];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值