zoukankan      html  css  js  c++  java
  • 停靠模式+GIF

    UIView *redView=[[UIView alloc]initWithFrame:CGRectMake(0,20,200,200)];

    redView.backgroundColor=[UIColor redColor];

    //允许子视图放大或缩小 默认autoresizeSubviews的就为YES

    redView.autoresizeSubview=YES;

    redView.tag=100;

    [self.window addSubview:redView];

    UIView *yellowView=[[UIView alloc]initWithFrame:CGRectMake(0,0,100,100)];

    //按照可缩放的高度进行放大或缩小

    yellowView.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexbleWidth;

    yellowView.backgroundColor=[UIColor yellowColor];

    [redView addSubview:yellowView];

    UIButton *btn=[UIButton buttonWithType:UIButtonTypeSystem];

    [btn setTitle:@"放大" forState:UIControlStateNormal];

    btn.frame=CGRectMake(100,300,100,30);

    [self.window addSubview:btn];

    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];

    -(void)btnClick:(UIButton *)bt

    {
    UIView *redView=[self.window viewWithTag:100];

    redView.frame=CGRectMake(redView.frame.origin.x,redView.frame.origin.y,redView.frame.size.width+10,redView.frame.size.height+10);

    }

    //GIF 用第三方库

    (1)

    //获得图片路径

    NSString *imgPath=[[NSBundle mainBundle]pathForResource:@"FlagZombie" ofType:@"gif"];

    //通过指定路径下的文件初始化NSData

    NSData *data=[[NSData alloc]initWithContentOfFile:imgPath];

    UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(100,100,50,50)];

    imgView.image=[UIImage animatedImageWithAnimatedGIFData:data];

    [self.window addSubview:imgView];

    (2)

    NSURL *url=[[NSBundle mainBundle]URLForResource:@"FlagZombie" withExtension:@"gif"];

    UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(200,100,80,80)];

    //通过类别中的方法animatedImageWithAnimatedGIFURL实现Gif的图片的播放

    imgView.imge=[UIImage animatedImageWithAnimatedGIFURL:url];

    imgView.tag=100;

    [self.window addSubview:imgView];

    //通过定时器实现每一段时间调用move方法

    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(move) userInfo:nil repeats:YES];

    -(void)move{
    UIImageView *imgView=(UIImageView *)[self.window viewWithTag:100];

    //当图片的x坐标大于80,没调用move都使图片向左侧偏移5个单位

    if(imgView.frame.origin.x>80){
    imgView.frame=CGRectMake(imgView.frame.origin.x-5,imgView.frame.origin.y,imgView.frame.size.width,imgView.frame.size.height);

         }

    }

  • 相关阅读:
    Java的参数传递是值传递还是引用传递
    10张图带你深入理解Docker容器和镜像
    Java 如何有效地避免OOM:善于利用软引用和弱引用
    事务与一致性:刚性or柔性
    Java 面试题史上最强整理
    三张图秒懂Redis集群设计原理
    iOS开发笔记系列-基础4(变量与数据类型)
    iOS开发笔记系列-基础3(多态、动态类型和动态绑定)
    iOS开发笔记系列-基础2(类)
    iOS开发笔记系列-基础1(数据类型与表达式)
  • 原文地址:https://www.cnblogs.com/y16879w/p/4415476.html
Copyright © 2011-2022 走看看