一. exclusiveTouch
exclusive
独有的;排外的;专一的
其源自UIView,字面意思其具有排他性,即会独占整个Touch事件,除非你手指离开屏幕,其他视图休想响应。手势识别(GestureRecognizers)会忽略此属性。
_ 用处:避免按钮同时被触发
二. 小片切图拉伸 避免平铺
my_head_bg_curve@2x.png // 公用代码
self.view.backgroundColor = [UIColor colorWithHex:0x2bc2f4];
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
[self.view addSubview:tempView];
- 实践一
UIImage *curveImage = [UIImage imageNamed:@"my_head_bg_curve"];
UIImage *newImage = [curveImage resizableImageWithCapInsets:UIEdgeInsetsMake(21, 0, 0, 0) resizingMode:UIImageResizingModeStretch];
tempView.backgroundColor = [UIColor colorWithPatternImage:newImage];```
实际效果:
![平铺](https://img.haomeiwen.com/i182827/b9951732afa38ecf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
-_-# 不带这样玩的
* 实践二 把图片扔到UIImageView里
[tempView addSubview:[self createCurveBackgroundView]]; //加到公用代码后面
- (UIImageView *)createCurveBackgroundView {
UIImage *curveImage = [UIImage imageNamed:@"my_head_bg_curve"];
UIImageView *imageView = [UIImageView new];
imageView.frame = CGRectMake(0, 30, kScreenWidth, kScreenHeight-30);
imageView.image = curveImage;
return imageView;
}```
实际效果:
-_-# 这是什么鬼
- 实践三
[tempView addSubview:[self createCurveBackgroundView]]; //加到公用代码后面
- (UIImageView *)createCurveBackgroundView {
UIImage *curveImage = [UIImage imageNamed:@"my_head_bg_curve"];
UIImage *newImage = [curveImage resizableImageWithCapInsets:UIEdgeInsetsMake(21, 0, 0, 0) resizingMode:UIImageResizingModeStretch];
UIImageView *imageView = [UIImageView new];
imageView.frame = CGRectMake(0, 30, kScreenWidth, kScreenHeight-30);
imageView.image = newImage;
return imageView;
}```
实际结果:
![完美.png](https://img.haomeiwen.com/i182827/bad1fbc5a49c29de.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
##### 三. 单例的实现方式
[Singleton实现](http://cocoa.venj.me/blog/singleton-in-objc/)
##### 四. 关于`UITableView`一个有趣的发现(`iOS8` 系统)
self.tableView.tableFooterView = [UIView new];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView registerClass:[MXTableViewCell class] forCellReuseIdentifier:@"MXTableViewCell"];```
-_-# 三句话以此顺序时(必崩),随便换个顺序(或 代理写在最后)就ok。(求解😢)
五. 数字格式化 NSNumberFormatter
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
NSString *string = [formatter stringFromNumber:[NSNumber numberWithInt:123456789]];
NSLog(@"Formatted number string:%@",string);
输出结果为:[1223:403] Formatted number string:123,456,789```
参考链接:[iOS中数字的格式化 NSNumberFormatter
](http://www.tuicool.com/articles/U3IV7f)
##### 六. Xcode `New Group` 如何本地生成物理文件夹
通常,创建文件夹的方式是桌面创建一个文件夹,然后拖进`Xcode`工程里
😊 [A command-line tool that reorganizes your Xcode project folder to match your Xcode groups](https://github.com/venmo/synx) ......打开这个链接,你会发现一切都是如此简单 😄😄😄
```$ sudo gem install synx // sudo使一般用户不需要知道超级用户的密码即可获得权限```
##### 七. block判空的优雅写法
!block ?: block()
参考链接:[[Why do nil / NULL blocks cause bus errors when run?](http://stackoverflow.com/questions/4145164/why-do-nil-null-blocks-cause-bus-errors-when-run)](http://stackoverflow.com/questions/4145164/why-do-nil-null-blocks-cause-bus-errors-when-run)
##### 八. UIImageView显示gif加载
NSURL *fileUrl = [[NSBundle mainBundle] URLForResource:@"1" withExtension:@"gif"];//加载GIF图片
CGImageSourceRef gifSource = CGImageSourceCreateWithURL((CFURLRef)fileUrl, NULL);//将GIF图片转换成对应的图片源
size_t frameCount=CGImageSourceGetCount(gifSource);//获取其中图片源个数,即由多少帧图片组成
NSMutableArray* frames=[[NSMutableArray alloc] init];//定义数组存储拆分出来的图片
for (size_t i=0; i < frameCount; i++) {
CGImageRef imageRef=CGImageSourceCreateImageAtIndex(gifSource, i, NULL);//从GIF图片中取出源图片
[frames addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen] orientation:UIImageOrientationUp]];
//将图片源转换成UIimageView能使用的图片源,将图片加入数组中
CGImageRelease(imageRef);
}
UIImageView* imageview=[[UIImageView alloc] initWithFrame:CGRectMake(20, 64, 40, 40)];
imageview.animationImages=frames;//将图片数组加入UIImageView动画数组中
imageview.animationDuration=3;//每次动画时长
[imageview startAnimating];//开启动画,此处没有调用播放次数接口,UIImageView默认播放次数为无限次,故这里不做处理
[self.view addSubview:imageview]; ```
九. Xcode8关闭系统log输出步骤
1.选择 Product -->Scheme-->Edit Scheme
2.选择 Arguments
3.在Environment Variables添加一个环境变量 OS_ACTIVITY_MODE 设置值为"disable"
十. 正确显隐导航栏的姿势
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
攒够10个😄😄😄,期待下一篇来临
网友评论