Day01
-
command + k
调出软键盘
-
UITextField
密文方式输入 Secure Text Entry
- 退出键盘
[self.view endEditing:YES];
- 在
Main.storyboard
control + 控件,便捷生成属性。
-
command + shift + h +h
切换到任务管理器
6.command + r
运行程序
-
command + shift + n
新建工程
-
command + enter
切换为一个试图
-
command + shift + enter
切换为两个试图
父View及子View
//superview 父View
// self.txt.superview.backgroundColor=[UIColor yellowColor];
//subviews 子view
// for (UIView *view in self.view.subviews) {
// view.backgroundColor=[UIColor redColor];
// }
//根据Tag找view
// UITextField *txt=[self.view viewWithTag:66];
// txt.text=@"hello";
//获取第一个对象
while(self.view.subviews.firstObject){
[self.view.subviews.firstObject removeFromSuperview];
}
Transform相关
- (IBAction)move {
// 2. 修改结构体值
// 下面这句话的意思是:告诉控件, 平移到距离原始位置-50的位置
//self.btnIcon.transform = CGAffineTransformMakeTranslation(0, -50); // 向上平移
// 基于一个旧的值, 在进行平移
// 基于现有的一个值, 再进行平移
self.btnIcon.transform = CGAffineTransformTranslate(self.btnIcon.transform, 0, 50);
}
- (IBAction)rotate {
// 45°
//self.btnIcon.transform = CGAffineTransformMakeRotation(-M_PI_4);
[UIView animateWithDuration:2.5 animations:^{
self.btnIcon.transform = CGAffineTransformRotate(self.btnIcon.transform, -M_PI_4);
self.btnIcon.transform = CGAffineTransformTranslate(self.btnIcon.transform, 0, 50);
self.btnIcon.transform = CGAffineTransformScale(self.btnIcon.transform, 1.5, 1.5);
}];
}
// 缩放
- (IBAction)scale {
//self.btnIcon.transform = CGAffineTransformMakeScale(0.5, 0.5);
self.btnIcon.transform = CGAffineTransformScale(self.btnIcon.transform, 1.5, 1.5);
}
// 让控件回到原始的位置
- (IBAction)goBack:(id)sender {
self.btnIcon.transform = CGAffineTransformIdentity;
}
读取pic.plist
- (NSArray *)pic
{
if (_pic == nil) {
// 写代码加载pic.plist文件中的数据到_pic
// 1. 获取pic.plist文件的路径
// 获取pic.plist文件的路径赋值给path变量
// [NSBundle mainBundle]表示获取这个app安装到手机上时的根目录
// 然后在app的安装的根目录下搜索pic.plist文件的路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"pic" ofType:@"plist"];
// 读取文件
NSArray *array = [NSArray arrayWithContentsOfFile:path];
_pic = array;
}
return _pic;
}
播放图片问题
// 执行动画的方法
- (void)startAnimating:(int)count picName:(NSString *)picName
{
// 如果当前图片框正在执行动画, 那么直接return, 什么都不做(没有开启一个新动画)
if (self.imgViewCat.isAnimating) {
return;
}
// 1. 把图片加载到数组中
// 0.动态加载图片到一个NSArray中
NSMutableArray *arrayM = [NSMutableArray array];
for (int i = 0; i < count; i++) {
// 拼接图片名称
NSString *imgName = [NSString stringWithFormat:@"%@_%02d.jpg", picName, i];
// 根据图片名称加载图片
// 通过imageNamed: 这种方式加载图片, 加载好的图片会一直保存写在内存中, 不会释放.这样下次如果再使用同样的图片的时候就不需要再重新加载了, 因为内存里面已经有了。缺点就是: 如果加载了大量的图片, 那么这些图片会一直保留在内存中,导致应用程序占用内存过大(这就叫缓存)
// 使用这种方式加载图片, 加载起来的图片即便没有强类型指针引用也不会销毁(会被缓存)
//UIImage *imgCat = [UIImage imageNamed:imgName];
// 使用下面这种方式加载的图片, 只要没有强类型指针引用就会被销毁了
// 解决: 换一种加载图片的方式, 不要使用缓存
// 获取图片的完成的路径
NSString *path = [[NSBundle mainBundle] pathForResource:imgName ofType:nil];
// 这里的参数不能再传递图片名称了, 这里需要传递一个图片的完整路径
UIImage *imgCat = [UIImage imageWithContentsOfFile:path];
// 把图片加载到数组中
[arrayM addObject:imgCat];
}
// 2. 设置UIImageView的animationImages属性为对应的图片集合
// self.imgViewCat.animationImages = arrayM;
[self.imgViewCat setAnimationImages:arrayM];
// 3. 动画持续时间
self.imgViewCat.animationDuration = self.imgViewCat.animationImages.count * 0.1;
// 4. 重复次数
self.imgViewCat.animationRepeatCount = 1;
// 5. 启动动画
[self.imgViewCat startAnimating];
// 清空图片集合
// 这样些写的问题是, 当动画启动以后, 动画还没开始执行, 就已经让图片集合清空了, 也就是说self.imgViewCat.animationImages 里面已经没有图片了, 所以动画就不执行了。
//self.imgViewCat.animationImages = nil;
// self.imgViewCat.animationImages = nil; 需要延迟一段时间执行, 当动画执行完毕以后再清空这些图片
//[self.imgViewCat setAnimationImages:nil];
// 设置图片框在调用setAnimationImages:nil方法的时候延迟执行
[self.imgViewCat performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.imgViewCat.animationImages.count * 0.1];
}
网友评论