1.NSBundle

1> 一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹

2> 利用mainBundle就可以访问软件资源包中的任何资源

3> 模拟器应用程序的安装路径

/Users/aplle/资源库/Application Support/iPhone Simulator/7.1/Applications

2.UIImageView和UIButton

1> 使用场合

* UIImageView: 如果仅仅是显示图片,不需要监听图片的点击

* UIButton: 既要显示图片,又要监听图片的点击

2> 相同:能显示图片

3> 不同点

* UIButton能处理点击事件, UIImageView不能处理点击事件

* UIButton既能显示图片, 又能显示文字

* UIButton能同时显示两张图片

* UIButton继承自UIControl, 因此默认就能处理事件

* UIImageView继承自UIView, 因此默认就不能处理事件

3.Xcode文档安装路径

/Applications/Xcode.app/Contents/Developer/Documentation/DocSets

4.Xcode模拟器安装路径

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs

5,UIView的常⻅见属性

➢ @property(nonatomic,readonly) UIView *superview;

➢ 获得⾃自⼰己的⽗父控件对象

➢ @property(nonatomic,readonly,copy) NSArray *subviews;

➢ 获得⾃自⼰己的所有⼦子控件对象

➢ @property(nonatomic) NSInteger tag;

➢ 控件的ID\标识,⽗父控件可以通过tag来找到对应的⼦子控件

➢ @property(nonatomic) CGAffineTransform transform;

➢ 控件的形变属性(可以设置旋转⾓角度、⽐比例缩放、平移等属性)

在OC中,通过transform属性可以修改对象的平移、缩放比例和旋转角度

常用的创建transform结构体方法分两大类

(1) 创建“基于控件初始位置”的形变

CGAffineTransformMakeTranslation(平移)

CGAffineTransformMakeScale(缩放)

CGAffineTransformMakeRotation(旋转)

(2) 创建“基于transform参数”的形变

CGAffineTransformTranslate

CGAffineTransformScale

CGAffineTransformRotate

补充:

在OC中,所有跟角度相关的数值,都是弧度值,180° = M_PI

正数表示顺时针旋转

负数表示逆时针旋转

提示:由于transform属性可以基于控件的上一次的状态进行叠加形变,例如,先旋转再平移。因此在实际动画开发中,当涉及位置、尺寸形变效果时,大多修改控件的transform属性,而不是frame、bounds、center 。

@property(nonatomic) CGRect frame; 控件所在矩形框在⽗父控件中的位置和尺⼨寸(以⽗父控件的左上⾓角为坐标原点)

@property(nonatomic) CGRect bounds; 控件所在矩形框的位置和尺⼨寸(以⾃自⼰己左上⾓角为坐标原点,所以bounds的x\y⼀一般

为0)

@property(nonatomic) CGPoint center;

控件中点的位置(以⽗父控件的左上⾓角为坐标原点)

6,UIView的常⻅见⽅方法

➢ - (void)addSubview:(UIView *)view;

➢ 添加⼀一个⼦子控件view

➢ - (void)removeFromSuperview;

➢ 从⽗父控件中移除

➢ - (UIView *)viewWithTag:(NSInteger)tag;

➢ 根据⼀一个tag标识找出对应的控件(⼀一般都是⼦子控件)

7,动画的两种创建方式

1)

//开始动画

[UIView beginAnimations:nil context:nil];

// 执行动画内容

self.headImageView.bounds=bounds;

// 设置动画时间

[UIView setAnimationDuration:2.0];

// 提交动画

[UIView commitAnimations];

2) // 一般用这种方式

UIView animateKeyframesWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> options:<#(UIViewKeyframeAnimationOptions)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>

8,汤姆猫中动画执行代码顺序

// 1,设置图片数组

self.tom.animationImages = images;

// 2.设置播放次数(1次)

self.tom.animationRepeatCount = 1;

// 3.设置播放时间

self.tom.animationDuration = images.count * 0.05;

// 4,开始动画

[self.tom startAnimating];

性能问题

// 加载图片

// imageNamed: 有缓存(传入文件名)

//        UIImage *image = [UIImage imageNamed:filename];

解决办法

// imageWithContentsOfFile: 没有缓存(传入文件的全路径)

NSBundle *bundle = [NSBundle mainBundle];

NSString *path = [bundle pathForResource:filename ofType:nil];

UIImage *image = [UIImage imageWithContentsOfFile:path];

动画放完1秒后清除内存

CGFloat delay = self.tom.animationDuration + 1.0;

[self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:delay];

代码图片浏览器动态代码:

模型类

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>@interface LLPic : NSObject// 图片地址
@property (nonatomic, copy) NSString *icon;// 图片
@property (nonatomic, strong) UIImage *image;// 描述
@property (nonatomic, copy) NSString *desc;+ (instancetype)picWithDic:(NSDictionary *)dic;
- (instancetype)initWithDic:(NSDictionary *)dic;+ (NSArray *)array;@end

#import "LLPic.h"@interface LLPic ()
{UIImage *_imageABC;
}
@end@implementation LLPic+ (NSArray *)array
{NSString *path = [[NSBundle mainBundle] pathForResource:@"images.plist" ofType:nil];NSArray *arrPic = [NSArray arrayWithContentsOfFile:path];NSMutableArray *arrPicMA = [[NSMutableArray alloc] initWithCapacity:arrPic.count];for (NSDictionary *dic in arrPic) {[arrPicMA addObject:[self picWithDic:dic]];}return arrPicMA;
}- (UIImage *)image
{if (!_imageABC) {_imageABC = [UIImage imageNamed:self.icon];}return _imageABC;
}- (instancetype)initWithDic:(NSDictionary *)dic
{if (self = [super init]) {[self setValuesForKeysWithDictionary:dic];}return self;
}+ (instancetype)picWithDic:(NSDictionary *)dic
{return [[self alloc] initWithDic:dic];
}@end

controller

#import "ViewController.h"
#import "LLPic.h"
@interface ViewController ()// 属性值必须改为strong,如果联系IBOutLet则为week
@property (nonatomic, strong) NSArray *picView;
@property (nonatomic, strong) UILabel *headLab;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIButton *leftBtn;
@property (nonatomic, strong) UIButton *rightBtn;
@property (nonatomic, strong) UILabel *footLab;
@property (nonatomic, strong) UIButton *leftRotationBtn; // 左旋转
@property (nonatomic, strong) UIButton *rightRotationBtn; // 右旋转
// 计数器
@property (nonatomic, assign) int index;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.self.view.backgroundColor = [UIColor purpleColor];[self loadPicView];
}#pragma mark - 按钮点击事件
// 左点击
- (void)leftBtnClick
{self.index--;[self loadPicView];
}
// 右点击
- (void)rightBtnClick
{self.index++;[self loadPicView];
}// 按钮旋转事件
- (void)rotationBtn:(UIButton *)btn
{[UIView animateWithDuration:0.2 animations:^{if (btn.tag == 20) {self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, M_PI_4);} else if (btn.tag == 40){self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, -M_PI_4);}}];
}#pragma mark - 展示界面
- (void)loadPicView
{// 1,拿出模型对象
    LLPic *pic = self.picView[self.index];self.headLab.text = [NSString stringWithFormat:@"%d/%ld", self.index+1, self.picView.count];self.imageView.image = [UIImage imageNamed:pic.icon];self.footLab.text = pic.desc;self.leftBtn.enabled = (self.index != 0);self.rightBtn.enabled = (self.index != (self.picView.count-1));// 2,加载按钮
    [self creatRoationBtn];}
#pragma mark - 懒加载控件,代码可读性强,并且提高性能
// headLab的加载
- (UILabel *)headLab
{if (!_headLab) {_headLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 300, 30)];_headLab.textAlignment = NSTextAlignmentCenter;[self.view addSubview:_headLab];}return _headLab;
}// imageView的加载
- (UIImageView *)imageView
{if (!_imageView) {_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(70, 70, 180, 180)];[self.view addSubview:_imageView];}return _imageView;
}// leftBtn的加载
- (UIButton *)leftBtn
{if (!_leftBtn) {_leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];_leftBtn.frame = CGRectMake(0,125, 40, 40);[_leftBtn setBackgroundImage:[UIImage imageNamed:@"left_normal"] forState:UIControlStateNormal];[_leftBtn setBackgroundImage:[UIImage imageNamed:@"left_highlighted"] forState:UIControlStateHighlighted];[_leftBtn setBackgroundImage:[UIImage imageNamed:@"left_disable"] forState:UIControlStateDisabled];// 按钮点击事件
        [_leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:_leftBtn];}return _leftBtn;
}// rightBtn的加载
- (void)creatRoationBtn
{_rightRotationBtn = [UIButton buttonWithType:UIButtonTypeCustom];_rightRotationBtn.frame = CGRectMake(200,400,40, 40);[_rightRotationBtn setBackgroundImage:[UIImage imageNamed:@"right_rotate_normal"] forState:UIControlStateNormal];[_rightRotationBtn setBackgroundImage:[UIImage imageNamed:@"right_rotate_highlighted"] forState:UIControlStateHighlighted];_rightRotationBtn.tag = 20;[_rightRotationBtn addTarget:self action:@selector(rotationBtn:) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:_rightRotationBtn];_leftRotationBtn = [UIButton buttonWithType:UIButtonTypeCustom];_leftRotationBtn.frame = CGRectMake(100,400,40, 40);[_leftRotationBtn setBackgroundImage:[UIImage imageNamed:@"left_rotate_normal"] forState:UIControlStateNormal];[_leftRotationBtn setBackgroundImage:[UIImage imageNamed:@"left_rotate_highlighted"] forState:UIControlStateHighlighted];_leftRotationBtn.tag = 40;[_leftRotationBtn addTarget:self action:@selector(rotationBtn:) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:_leftRotationBtn];}
- (UIButton *)rightBtn
{if (!_rightBtn) {_rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];_rightBtn.frame = CGRectMake(280,125,40, 40);[_rightBtn setBackgroundImage:[UIImage imageNamed:@"right_normal"] forState:UIControlStateNormal];[_rightBtn setBackgroundImage:[UIImage imageNamed:@"right_highlighted"] forState:UIControlStateHighlighted];[_rightBtn setBackgroundImage:[UIImage imageNamed:@"right_disable"] forState:UIControlStateDisabled];[_rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:_rightBtn];}return _rightBtn;}// 描述lab
- (UILabel *)footLab
{if (!_footLab) {_footLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 260, 300, 60)];_footLab.textAlignment = NSTextAlignmentCenter;_footLab.numberOfLines = 0;[self.view addSubview:_footLab];}return _footLab;
}#pragma mark - 加载数据模型
- (NSArray *)picView
{if (!_picView) {_picView = [LLPic array];}return _picView;
}@end

完成展示:

转载于:https://www.cnblogs.com/-boy/p/4106818.html

UI基础UIView常见属性及方法相关推荐

  1. iPone应用开发 UIView 常用属性和方法

    程序开发-uiview常用属性和方法">iPone应用程序开发 UIView常用属性和方法 常用属性 alpha 视图的透明度0.0f - 1.0f backgroundColor 视 ...

  2. TWebBrowser的常见属性和方法

    GoBack:方法,后退到上一个页面. GoForward:方法,前进到下一个页面. GoHome:方法,调用默认的主页页面,该页面在IE的选项中设定. GoSearch:方法,调用默认的搜索页面,该 ...

  3. 基础:常见的参数估计方法——MLE和MAP

    抽样.样本数据 -->观察数据趋势 -->选择模型 -->模型参数估计 -->假设检验 类别 名称 核心函数 求解目标 点估计 最小二乘法 模型参数的误差平方和函数 求偏导数, ...

  4. Python Django HttpRequest请求对象常见属性和方法

  5. UIView常见属性

    @property(nonatomic) CGRect frame; 控件所在矩形框在父控件中的位置和尺寸(以父控件的左上角为坐标原点) 可以定义控件的位置origin和大小size @propert ...

  6. ios开发-UI基础-应用管理(单纯界面)

    功能分析 以九宫格的形式展示应用信息 点击下载按钮后,做出相应操作(弹出一个提示"正在下载",相应应用的下载按钮变为"已下载") 步骤分析 搭建UI界面 加载应 ...

  7. windows media player控件播放器属性及方法使用

    wmp 9.0控件常见属性和方法 [基本属性] URL:String; 指定媒体位置,本机或网络地址 ui Mode:String; 播放器界面模式,可为Full, Mini, None, Invis ...

  8. JS 之Node节点的 属性、方法 获取

    JS Node节点的常见属性和方法使用 & 如何获取相应节点和值 一.节点的常用属性和方法 (一)通过具体的元素节点调用如下方法和属性 <1>getElementsByTagNam ...

  9. iOS开发UI篇 -- UISearchBar 属性、方法详解及应用(自定义搜索框样式)

    很多APP都会涉及到搜索框,苹果也为我们提供了默认的搜索框UISearchBar.但实际项目中我们通常需要更改系统默认搜索框的样式.为了实现这一目标,我们需要先搞懂 UISearchBar 的属性及方 ...

  10. iOS开发UI基础—手写控件,frame,center和bounds属性

    iOS开发UI基础-手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...

最新文章

  1. ​北京大学吴华君组诚聘医学/生信助理研究员和博士后
  2. 学python需要安装什么软件-学武汉Python培训课程需要安装什么软件?分享这10款...
  3. 数组中的元素赋值给元素_漫画:寻找无序数组的第k大元素
  4. ArcGIS实验教程——实验六:空间数据格式转换
  5. Eigen官网教程(2) Array类和元素级操作
  6. link怎么打开 vs2015_VS2015工程转VS2010
  7. 三管齐下!TB 级文件的上传性能瞬间被优化 100 倍!
  8. 项目:聊天室思路(linux下实现,语言:C/C++)
  9. JAVA后端开发常用的Linux命令总结
  10. 用Python实现开心消消乐小游戏
  11. 社会工程学部分攻击经典方法总结
  12. java求一元二次方程:ax2+bx+c=0的根
  13. Eclipse 启动时提示loading workbench错误并提示查看.log
  14. 163邮箱,163vip的邮箱收费标准是什么?
  15. WPF中播放GIF图片
  16. yapi文档转换jmx脚本
  17. 爬虫实践:爬取搜狗图片
  18. 游戏联运是指什么?具体该怎么做?
  19. 蒙塔卡洛模拟,Monte Carlo method
  20. 人脸反欺诈数据集的预处理过程(含代码)

热门文章

  1. 【GNN综述】图神经网络的解释性综述
  2. 【IPM2020】一种处理多标签文本分类的新颖推理机制
  3. 【KDD20】TAdaNet: 用于图增强元学习的任务自适应网络
  4. 【对话】对话系统经典:检索式对话
  5. 每日算法系列【LeetCode 684】冗余连接
  6. 基于MVC的JavaScriptWeb富应用开发
  7. Linux下通过WebShell反弹Shell的技巧
  8. vc++中进程通信之剪贴板常用函数
  9. 「三分钟系列05」3分钟看懂并发与并行
  10. Scikit-learn:主要模块和基本使用方法