IOS学习 动画和绘画:UIView基础动画

@interface HomeViewController : UIViewController


@property (weak, nonatomic) IBOutlet UIView *myView;

- (IBAction)startAnimation:(UIButton *)sender;


@property (weak, nonatomic) IBOutlet UIView *parentView;

- (IBAction)transitionAction:(UIButton *)sender;


@end



@implementation HomeViewController


- (IBAction)startAnimation:(UIButton *)sender {

//    [UIView beginAnimations:@"testAnimation" context:nil]; //设置动画名称

//    [UIView setAnimationDuration:0.5];//设置动画时长

//    //默认动画效果

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

//    [UIView setAnimationDelegate:self];  //设置代理

//    [UIView setAnimationDidStopSelector:@selector(animationStop)];    

//    

//    CGRect frame = self.myView.frame;

//    frame.origin.y = 500;

//    

//    self.myView.frame = frame;

//    

//    [UIView commitAnimations];//动画结束

    

    //透明度

    self.view.alpha =1;

    //缩放

    self.myView.transform = CGAffineTransformScale(self.myView.transform,1,1);

    

    //block方法

    [UIViewanimateWithDuration:0.7animations:^{

        //改变Y轴位置

//        CGRect frame = self.myView.frame;

//        frame.origin.y += 400;

//        self.myView.frame = frame;

        //设置动画重复执行

        [UIViewsetAnimationRepeatCount:1000];

        //改变透明度

        self.view.alpha =0.1;

        //大小缩放,不能设值为0,可以设一个很小的数

        self.myView.transform =CGAffineTransformScale(self.myView.transform,0.010.01);

    }completion:^(BOOL finished){

        if (finished) {

            [UIViewanimateWithDuration:0.7animations:^{

//                CGRect frame = self.myView.frame;

//                frame.origin.y -= 400;

//                self.myView.frame = frame;

                self.view.alpha =1;

                //恢复原始大小

                self.myView.transform =CGAffineTransformIdentity;

            }];

        }

    }];    

}


//-(void)animationStop{

//    [UIView beginAnimations:nil context:nil];

//    [UIView setAnimationDuration:0.5];

//    CGRect frame = self.myView.frame;

//    frame.origin.y -= 300;

//    self.myView.frame = frame;

//    [UIView commitAnimations];

//}


- (IBAction)transitionAction:(UIButton *)sender {

//    [UIView beginAnimations:nil context:nil];

//    [UIView setAnimationDuration:1];

//    //设置动画样式

//    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.parentView cache:YES];

//    [UIView commitAnimations];

    //视图索引变换

    [self.parentView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

//

    //block方法

    [UIView transitionWithView:self.parentView duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{

        //[self.parentView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

    } completion:NULL];

}

@end




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值