UIKit动画

2020-10-30  本文已影响0人  我不白先生

ios动画

#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView2;
@end
@implementation ViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    /********************imageView2动画************************/
    NSMutableArray *mArray = [NSMutableArray array];
    for(NSInteger i = 0; i  < 12 ; i++){
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"xiaolu%02ld",i+1]];
        [mArray addObject:image];
    }
    //将图片对象数组 赋值给imageView2.animationImages属性
    self.imageView2.animationImages = mArray;
    //设置动画时长
    self.imageView2.animationDuration = 3;
    //动画重复次数  设置为0 是无限循环
    self.imageView2.animationRepeatCount = 8;
    //开始运行动画
    [self.imageView2 startAnimating];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    /********************imageView动画************************/
    //自动去找xiaolu1、2、3、4图片
    UIImage *image = [UIImage animatedImageNamed:@"xiaolu0" duration:1];
    self.imageView.image = image;
}
image.png
image.png
image.png
image.png
image.png
image.png
image.png

ViewController.m

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation ViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
   // [UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>]
   /**
    @param  Duration  持续时间
    @param  deplay    延迟时间 动画等待多长时间开始运行
    @param  options   动画选项
    @param  animations 动画体 里面写视图动画结束时的状态
    @param  completion  动画完成时 做什么事
    
    */
  //[UIView animateWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> options:<#(UIViewAnimationOptions)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>
    [UIView animateWithDuration:3 animations:^{
        //        //设置结束位置一般用中心点center改变位置
        self.imageView.center = CGPointMake(150, 700);
        //        //设置结束透明度
        self.imageView.alpha = 1;
        //设置结束大小
        CGRect bounds = self.imageView.frame;
        bounds.size =CGSizeMake(400, 250);
        self.imageView.bounds = bounds;
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //设置起始位置
    self.imageView.center = CGPointMake(50, 50);
    //设置起始透明度
    self.imageView.alpha = 0;
    self.imageView.bounds = CGRectMake(0, 0, 200, 100);
}
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIView *myView;
@property(nonatomic,assign)CGFloat viewHeight;
@end
@implementation ViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //设置UIView动画4秒钟高度从0变成view自身的高度
    [UIView animateWithDuration:4 animations:^{
        CGRect frame = self.myView.frame;
        frame.size.height = self.viewHeight;
        self.myView.frame = frame;
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    CGRect frame = self.myView.frame;
    self.viewHeight = frame.size.height;
    frame.size.height = 0;
    self.myView.frame = frame;
}
上一篇 下一篇

猜你喜欢

热点阅读