UIView 动画

本文介绍如何使用UIView动画方法实现各种视图动画效果,包括左右翻转、旋转、移动、翻页及缩放等操作,并详细解释了每个动画方法的具体参数设置。

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

/// 左右翻转

- (void)animFlipFromLeft {

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

    //设置时常

    [UIView setAnimationDuration:1];

    //设置动画淡入淡出

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    //设置翻转方向

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft

                           forView:self

                             cache:YES];

    [UIView commitAnimations];

}


- (void)animFlipFromRight {

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

    //设置时常

    [UIView setAnimationDuration:1];

    //设置动画淡入淡出

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    //设置翻转方向

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight

                           forView:self

                             cache:YES];

    [UIView commitAnimations];

}


/// 旋转

- (void)animRotate:(int)angle {

    CGAffineTransform  transform;

    transform = CGAffineTransformRotate(self.transform,M_PI/360 * angle);

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

    [UIView setAnimationDuration:2];

    [self setTransform:transform];

    [UIView commitAnimations];

}


/// 移动

- (void)animMove:(CGRect)rc {

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

    [UIView setAnimationDuration:2];

    self.frame=rc;

    [UIView commitAnimations];

}


/// 翻页

- (void)animCurlUp {

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

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//指定动画曲线类型

    [UIView setAnimationDuration:1];

    [UIView setAnimationDelegate:self];

    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp

                           forView:self

                             cache:YES];

    [UIView commitAnimations];

}


/// 缩放

- (void)animScale {

    CGAffineTransform  transform;

    transform = CGAffineTransformScale(self.transform,1.2,1.2);

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

    [UIView setAnimationDuration:2];

    [UIView setAnimationDelegate:self];

    [self setTransform:transform];

    [UIView commitAnimations];

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值