UIView的四种动画(类似于下拉刷新的动画效果)

定义属性

@property(nonatomic,retain)UIView *myView;

创建

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.myView=[[UIView alloc] initWithFrame:CGRectMake(100, 100, 150, 0)];
    self.myView.backgroundColor=[UIColor yellowColor];
    [self.view addSubview:self.myView];

    UIButton *button=[UIButton buttonWithType:UIButtonTypeSystem];
    button.frame=CGRectMake(100, 300, 150, 50);
    [button setTitle:@"点击" forState: UIControlStateNormal];
    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside ];
    [self.view addSubview:button];
}

点击方法

-(void)click:(UIButton *)button{
    //1.动画(动画从起始位置移动到指定位置)
    //参数1:动画的播放时长,单位秒
    //参数2:把要实现的动画效果,放到block去完成
//    [UIView animateWithDuration:2 animations:^{
//        self.myView.frame=CGRectMake(0, 0, 50, 50);
//        self.myView.backgroundColor=[UIColor cyanColor];
//设置透明度,如果透明度是1,动画在移动过程中颜色也会渐变
//        self.myView.alpha=0;
//    }];

    //UIView的第二种动画效果(放大缩小,可以恢复原状)(动画下拉并回收)
//    [UIView animateWithDuration:2 animations:^{
//        self.myView.frame=CGRectMake(100, 100, 150, 100);
//    } completion:^(BOOL finished) {
//        self.myView.backgroundColor=[UIColor cyanColor];
//        [UIView animateWithDuration:2 animations:^{
//            self.myView.frame=CGRectMake(100, 100, 150, 0);
//        }];
//    }];
//    


    //UIView的第三种动画(动画下拉并回收,可以设置延时)
    //参数2:延时多久执行
//    [UIView animateWithDuration:2 delay:0.1 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse  animations:^{
//        self.myView.frame=CGRectMake(100, 100, 150, 200);
//    } completion:^(BOOL finished) {
//        [UIView animateWithDuration:2 animations:^{
//            self.myView.frame=CGRectMake(100, 100, 150, 0);
//        }];
//    }];

    //UIView动画的第四种(动画下拉,并震动)
    //参数3:震动的幅度,越小越大
    //参数4:初始速度,越大越快
    [UIView animateWithDuration:2 delay:0.1 usingSpringWithDamping:0.1 initialSpringVelocity:100 options: UIViewAnimationOptionRepeat animations:^{
        self.myView.frame=CGRectMake(100, 100, 150, 200);
    } completion:^(BOOL finished) {

    }];



}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值