20150701_UI之UIImageView使用
2015-07-03 22:41
375 查看
UIImageView使用代码实例:
代码中的图片可以自己找,将图片添加到工程中即可,通过图片名就能找到它
代码中的图片可以自己找,将图片添加到工程中即可,通过图片名就能找到它
// // ViewController.m // IOS150701_UI(03)_UIImageView // // Created by PengJunlong on 15/7/1. // Copyright (c) 2015年 Peng Junlong. 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 显示图片的view //找到名称为map,扩展名是png的资源 NSString *path = [[NSBundle mainBundle] pathForResource:@"map" ofType:@"png"]; //加载的图片一直在内存中,占用内存,效率高,通常用来加载小的图片 //UIImage *image = [[UIImage imageNamed: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 *anImageView = [[UIImageView alloc] initWithFrame:CGRectMake(200, 200, 50, 50)]; anImageView.tag = 100; anImageView.animationImages = imageArray; //设置动画播放时间间隔 anImageView.animationDuration = 2; //开始播放动画 [anImageView startAnimating]; [imageView addSubview:anImageView]; } - (void)tapImageView { NSLog(@"Map被点击"); 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
相关文章推荐
- 20150701_UI之UIView层操作
- 20150630_UI之计算器练习
- 20150630_UI之ViewCrontroller初步认识
- 【HM】第8课:Request与Response详解
- 20150630_UI之按钮UIButton使用
- 20150629_UI之坐标系及UILabel的练习
- 20150629_UI之坐标系及UILabel
- 20150629_UI之应用程序生命周期及UI开源学习网址
- android.support.v7导入时候报values-v21.xml里面资源文件找不到
- IOS--UI--LessonTouchView 触摸事件 & 响应者链
- 常用的JS插件介绍:3、masonry——瀑布流(结合requirejs、art-template、infinite-scroll)
- awk built-in functions
- Android UI 调试常用工具(Dump view UI hierarchy for Automator)
- 初步探索java中的UUID
- IOS--UI--LessonCustumView 自定义视图
- android ndk-build IncrediBuild 分布式编译设置
- foundation-NSValue
- UI基础:事件.响应链
- UI基础:事件.响应链 分类: iOS学习-UI 2015-07-03 19:51 1人阅读 评论(0) 收藏
- iOS 优化UITableViewCell高度计算的那些事