iOS学习之动画效果的实现

来源:互联网 发布:红旗linux界面图 编辑:程序博客网 时间:2024/04/30 09:21

//

//  ViewController.m

//  UI-动画练习

//

//  Created by jzq_mac on 15/7/22.

//  Copyright (c) 2015 jzq_mac. All rights reserved.

//


#import "ViewController.h"


@interfaceViewController ()

{

    UIImageView *animation;

    UIView *view;

    UIView *view1;

}

@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    [selfcreatView];

    


    


    


    [NSTimerscheduledTimerWithTimeInterval:10target:selfselector:@selector(creatView)userInfo:nilrepeats:YES];


}



- (void)creatView

{

   //动态图并移动动态图

    animation = [[UIImageViewalloc]initWithFrame:CGRectMake(86,0, 200,200)];

    animation.layer.cornerRadius =100;

    animation.layer.masksToBounds =YES;

    NSMutableArray *list = [NSMutableArrayarray];

    for (int i =1; i <= 15; i++) {

        NSString *name = [NSStringstringWithFormat:@"动态猫-%d(被拖移).tiff",i];

        [listaddObject:[UIImageimageNamed:name]];

    }

    

    animation.animationImages = list;

    animation.animationDuration =5;

    animation.animationRepeatCount = -1;

    [animationstartAnimating];

    

    

    [UIViewanimateWithDuration:5animations:^{animation.frame =CGRectMake(86,500, 200,200 );}completion:^(BOOL finishied){[UIViewanimateWithDuration:5animations:^{animation.frame =CGRectMake(86,0, 200,200);}];}];

    [self.viewaddSubview:animation];

    

    

    //   移动视图

    self.view.backgroundColor = [UIColorgrayColor];

    view =[[UIViewalloc]initWithFrame:CGRectMake(0,0, 100,100)];

    view.backgroundColor = [UIColorredColor];

    view.layer.cornerRadius =50;

    [self.viewaddSubview:view];

    

    [UIViewanimateWithDuration:5animations:^{view.frame =CGRectMake(275,550, 100, 100);}completion:^(BOOL finished){[UIViewanimateWithDuration:5animations:^{view.frame =CGRectMake(0,0, 100,100);}];}];

    view.alpha =1;

    [UIViewanimateWithDuration:10animations:^{view.alpha =0;}];

    

    

    view1 =[[UIViewalloc]initWithFrame:CGRectMake(275,0, 100,100)];

    view1.backgroundColor = [UIColoryellowColor];

    view1.layer.cornerRadius =50;

    [self.viewaddSubview:view1];

    

    view1.alpha =1;

    [UIViewanimateWithDuration:10animations:^{view1.alpha =0;}];

    

    [UIViewanimateWithDuration:5animations:^{view1.frame =CGRectMake(0,550, 100, 100);}completion:^(BOOL finished){[UIViewanimateWithDuration:5animations:^{view1.frame =CGRectMake(275,0, 100,100);}];}];

}






//- (void)click:(UIButton *)sender

//{

//    if (sender.selected !=YES ) {

//        sender.selected = YES;

//        [animation startAnimating];

//        [sender setTitle:@"开始" forState:UIControlStateNormal];

//        

//    }else{

//        sender.selected = NO;

//        [animation stopAnimating];

//        [sender setTitle:@"暂停" forState:UIControlStateSelected];

//    }

//}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


0 0
原创粉丝点击