zoukankan      html  css  js  c++  java
  • UI4_UIImageView

    //
    //  ViewController.m
    //  UI4_UIImageView
    //
    //  Created by zhangxueming on 15/7/1.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        //ImageView --- 显示图片
        
        NSString *path =[[NSBundle mainBundle] pathForResource:@"map" ofType:@"png"];
        //NSLog(@"path = %@", path);
    
        //加载图片,通常加载大图片,效率低一点
        UIImage *image = [UIImage imageWithContentsOfFile:path];
        
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.frame =CGRectMake(10, 100, self.view.frame.size.width-20, 400);
        [self.view addSubview:imageView];
        
        //添加手势
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView)];
        //设置点击次数
        tap.numberOfTapsRequired = 1;
        //设置触摸点个数
        tap.numberOfTouchesRequired = 1;
        //使能imageView用户交互
        imageView.userInteractionEnabled =YES;
        //添加手势到imageView上
        [imageView addGestureRecognizer:tap];
        
        
        NSMutableArray *imageArray = [NSMutableArray array];
        for (int i=0; i<12; i++) {
            NSString *imageName = [NSString stringWithFormat:@"player%d",i+1];
            UIImage *image = [UIImage imageNamed:imageName];
            [imageArray addObject:image];
        }
        
        UIImageView *aniImageView = [[UIImageView alloc] initWithFrame:CGRectMake(150, 200, 100, 100)];
        aniImageView.tag = 100;
        aniImageView.animationImages =imageArray;
        //
        [self.view addSubview:aniImageView];
        
        //设置动画播放时间
        aniImageView.animationDuration = 2.0;
        //开始播放动画
        [aniImageView startAnimating];
        
    }
    
    - (void)tapImageView
    {
        NSLog(@"imageView 被点击");
        static BOOL aniState = YES;
        UIImageView *imageView = (UIImageView *)[self.view viewWithTag:100];
        if (aniState) {
            [imageView stopAnimating];
            aniState = NO;
        }
        else
        {
            [imageView startAnimating];
            aniState = YES;
        }
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
    
  • 相关阅读:
    CF932E Team Work
    BZOJ 4480 [JSOI2013] 快乐的jyy
    CF285E Positions in Permutations
    P4312 [COCI 2009] OTOCI / 极地旅行社
    P3327 [SDOI2015]约数个数和
    P3649 [APIO2014]回文串
    P3181 [HAOI2016]找相同字符
    P3346 [ZJOI2015]诸神眷顾的幻想乡
    P4248 [AHOI2013]差异
    P4512 【模板】多项式除法
  • 原文地址:https://www.cnblogs.com/0515offer/p/4638454.html
Copyright © 2011-2022 走看看