当前位置: 首页 > news >正文

UIImageView -- 选择图片、循环播放

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

 初始化:

UIImageView *_imageView = [[UIImageView alloc] init];
//其他初始化
/*
initWithFrame:<#(CGRect)#>
initWithCoder:<#(nonnull NSCoder *)#>
initWithImage:<#(nullable UIImage *)#>
initWithImage:<#(nullable UIImage *)#> highlightedImage:<#(nullable UIImage *)#>
*/

 显示方式:居中、左、右,填充、拉伸、适应,和设置屏保差不多,就不上图了。

_imageView.contentMode = UIViewContentModeScaleToFill;
//其他方式
/*
typedef NS_ENUM(NSInteger, UIViewContentMode) {
    UIViewContentModeScaleToFill,
    UIViewContentModeScaleAspectFit,      // contents scaled to fit with fixed aspect. remainder is transparent
    UIViewContentModeScaleAspectFill,     // contents scaled to fill with fixed aspect. some portion of content may be clipped.
    UIViewContentModeRedraw,              // redraw on bounds change (calls -setNeedsDisplay)
    UIViewContentModeCenter,              // contents remain same size. positioned adjusted.
    UIViewContentModeTop,
    UIViewContentModeBottom,
    UIViewContentModeLeft,
    UIViewContentModeRight,
    UIViewContentModeTopLeft,
    UIViewContentModeTopRight,
    UIViewContentModeBottomLeft,
    UIViewContentModeBottomRight,
};
*/

自动布局:

        _imageView.autoresizingMask =
        UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

/*
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
    UIViewAutoresizingNone                 = 0,
    UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
    UIViewAutoresizingFlexibleWidth        = 1 << 1,
    UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
    UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
    UIViewAutoresizingFlexibleHeight       = 1 << 4,
    UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
*/

循环播放图片:

    UIImage *image1 = [UIImage imageNamed:@"1"];
    UIImage *image2 = [UIImage imageNamed:@"2"];
    UIImage *image3 = [UIImage imageNamed:@"3"];
    NSArray *imagesArray = @[image1,image2,image3];
    
    _imageView.animationImages = imagesArray;
    _imageView.animationDuration = [imagesArray count];
    //循环次数
    _imageView.animationRepeatCount = 0;
    [_imageView startAnimating];

加载图片:

    UIImage *image1 = [UIImage imageNamed:@"1"];
    UIImage *image2 = [UIImage imageWithContentsOfFile:@"filePath"];
    UIImage *image3 = [UIImage imageWithData:<#(nonnull NSData *)#>];
//image1、image2 会在内存中做缓存,图片多了消耗内存,但同一张图片只缓存一次,可重复利用。
//image3 以数据方式加载,展示网络图片,或者存储数据库展示图片,

 

实例:选择图片

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    
    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
    [self.view addSubview:_imageView];
    _imageView.backgroundColor = [UIColor redColor];
    //
    
    _imageView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(choosePictrue)];
    //tap.numberOfTapsRequired  = 2;
    [_imageView addGestureRecognizer:tap];
    [tap release];
    [_imageView release];
        
}

- (void)choosePictrue{
    UIImagePickerController *picc = [[UIImagePickerController alloc] init];
    picc.delegate = self;
    picc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:picc animated:YES completion:nil];
    [picc release];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    _imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [picker dismissViewControllerAnimated:YES completion:nil];
    
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{

    [picker dismissViewControllerAnimated:YES completion:nil];
}
@end

 

 

转载于:https://my.oschina.net/liuchuanfeng/blog/214422

相关文章:

  • JTree/DefaultMutableTreeNode 树形结构
  • 各大银行的收发标准
  • CSS 元素透明
  • 【转】网站布局--瀑布流式布局
  • 使用Python实现Hadoop MapReduce程序
  • centos svn快速搭建
  • 一个IO的传奇一生(8) -- elevator子系统
  • linux:shell脚本格式
  • CSS自定义select下拉选择框(不用其他标签模拟)
  • 关于一级指针和二级指针作为参数的探究
  • 2014年4月15日星期二java学习历程
  • Amazon Workspace DaaS服务快速导读
  • http 错误
  • Unity3d 屏幕截图。并保存。iOS
  • quota .1
  • exif信息对照
  • iOS | NSProxy
  • js写一个简单的选项卡
  • LeetCode刷题——29. Divide Two Integers(Part 1靠自己)
  • ReactNativeweexDeviceOne对比
  • Service Worker
  • SpiderData 2019年2月25日 DApp数据排行榜
  • webpack+react项目初体验——记录我的webpack环境配置
  • 仿天猫超市收藏抛物线动画工具库
  • 快速体验 Sentinel 集群限流功能,只需简单几步
  • 微信小程序开发问题汇总
  • 一个SAP顾问在美国的这些年
  • 责任链模式的两种实现
  • ​​​​​​​Installing ROS on the Raspberry Pi
  • # 学号 2017-2018-20172309 《程序设计与数据结构》实验三报告
  • #QT(TCP网络编程-服务端)
  • #调用传感器数据_Flink使用函数之监控传感器温度上升提醒
  • (1)(1.13) SiK无线电高级配置(六)
  • (10)工业界推荐系统-小红书推荐场景及内部实践【排序模型的特征】
  • (13):Silverlight 2 数据与通信之WebRequest
  • (pt可视化)利用torch的make_grid进行张量可视化
  • (rabbitmq的高级特性)消息可靠性
  • (二)斐波那契Fabonacci函数
  • (附源码)springboot宠物医疗服务网站 毕业设计688413
  • (附源码)ssm基于jsp的在线点餐系统 毕业设计 111016
  • (附源码)计算机毕业设计大学生兼职系统
  • (蓝桥杯每日一题)love
  • (原創) 未来三学期想要修的课 (日記)
  • .net 4.0 A potentially dangerous Request.Form value was detected from the client 的解决方案
  • .NET CORE 3.1 集成JWT鉴权和授权2
  • .NET HttpWebRequest、WebClient、HttpClient
  • .NET6 开发一个检查某些状态持续多长时间的类
  • .netcore 获取appsettings
  • .NET的数据绑定
  • .NET简谈设计模式之(单件模式)
  • .NET使用HttpClient以multipart/form-data形式post上传文件及其相关参数
  • .net与java建立WebService再互相调用
  • @拔赤:Web前端开发十日谈
  • [ CTF ]【天格】战队WriteUp- 2022年第三届“网鼎杯”网络安全大赛(青龙组)
  • []常用AT命令解释()