知识点小结:
1.[[[UIApplication sharedApplication] keyWindow] endEditing:YES];// 收起键盘
// 点击发送按钮 发送消息
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[self commentOrRepleyFrequency];
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
// 设置音频回复类型为评论
self.type = ZHFrequencyCommentType;
}
2.iOS 11 适配---> 返回按钮向下偏移
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
3.设置按钮字体描边
btn.layer.shadowColor = [UIColor blackColor].CGColor;
btn.layer.shadowOffset = CGSizeMake(1, 1);
btn.layer.shadowOpacity = 0.5;
btn.layer.shadowRadius = 2;
4.当出现状态栏的时候,状态栏不接受点击事件,所以按钮的点击范围在状态栏周围的时候为无效点击范围?
查看图层发现项目中运用的三方(横屏播放视频)在我的视图层上方,所以点击方法被屏蔽,所以不响应下方点击方法
5.UIButton文字换行
在通常的开发中,有时候需求是这样的,需要在按钮中用两行或者多行文字显示,如图:
Paste_Image.png
通常的做法的话,我们会直接想到在UIButton中添加子控件UILabel,但是下面介绍一个更简单的方法:
1.xib/storyboard中:
在Line Break中选择Word Wrap,然后在title中用Optional+回车换行
2.代码:
设置Btn.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
设置文字的时候用\n就可
6.UICollectionView发生IndexPath.row发生不更新的状况--->MGJ,大Bug
[self.collectionView performBatchUpdates:^{
ZHLog(@"%ld", indexPath.row);
[JohnAlertManager showWaringMessageAlert:[NSString stringWithFormat:@"%ld", indexPath.row]];
[_arr removeObjectAtIndex:indexPath.row];
[collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
} completion:^(BOOL finished) {
[self.collectionView reloadData];
}];
7.iOS 复制文字信息到剪切板
[[UIPasteboard generalPasteboard] setString:_textLabel.text];
8.项目中要求将Token传递到Web端,代码如下:
// 创建WKWebView
WKWebView *webView = [[WKWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
// 将WKWebView添加到当前View
[self.view addSubview:webView];
// 设置访问的URL
NSURL *url = [NSURL URLWithString:@"http://www.example.com"];
// 根据URL创建请求
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
// 设置请求方法为POST
[request setHTTPMethod:@"POST"];
// 设置请求参数
[request setHTTPBody:[@"username=aaa&password=123" dataUsingEncoding:NSUTF8StringEncoding]];
// 实例化网络会话
NSURLSession *session = [NSURLSession sharedSession];
// 创建请求Task
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
// 将请求到的网页数据用loadHTMLString 的方法加载
NSString *htmlStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[webView loadHTMLString:htmlStr baseURL:nil];
}];
// 开启网络任务
[task resume];
调研地址:
http://www.jianshu.com/p/403853b63537
9.类似于映客NavigationBar和TabBar隐藏显示的效果:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//scrollView已经有拖拽手势,直接拿到scrollView的拖拽手势
UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer;
//获取到拖拽的速度 >0 向下拖动 <0 向上拖动
CGFloat velocity = [pan velocityInView:scrollView].y;
if (velocity < -5) {
//向上拖动,隐藏导航栏
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self setTabBarHidden:YES];
}else if (velocity > 5) {
//向下拖动,显示导航栏
[self.navigationController setNavigationBarHidden:NO animated:YES];
[self setTabBarHidden:NO];
}else if(velocity == 0){
//停止拖拽
}
}
#pragma mark - privite
//隐藏显示tabbar
- (void)setTabBarHidden:(BOOL)hidden
{
UIView *tab = self.tabBarController.view;
CGRect tabRect = self.tabBarController.tabBar.frame;
if ([tab.subviews count] < 2) {
return;
}
UIView *view;
if ([[tab.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]]) {
view = [tab.subviews objectAtIndex:1];
} else {
view = [tab.subviews objectAtIndex:0];
}
if (hidden) {
view.frame = tab.bounds;
tabRect.origin.y = ZHScreenH + self.tabBarController.tabBar.zh_height;
} else {
view.frame = CGRectMake(tab.bounds.origin.x, tab.bounds.origin.y, tab.bounds.size.width, tab.bounds.size.height);
tabRect.origin.y = ZHScreenH - self.tabBarController.tabBar.zh_height;
}
[UIView animateWithDuration:0.25f animations:^{
self.tabBarController.tabBar.frame = tabRect;
}completion:^(BOOL finished) {
}];
}
修改项目相关bug
1.bug:送礼界面出现点击就返回到第一页
_collectionView.pagingEnabled = YES;
2.礼物界面需要适配
if (ZHScreenW>375) {
layout.itemSize = CGSizeMake(ZHScreenW/4, 375/4);
} else {
layout.itemSize = CGSizeMake(ZHScreenW/4, ZHScreenW/4);
}
3.礼物界面偏移量不正确
// 错误
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
ZHLog(@"%f", self.collectionView.contentOffset.x);
// 计算偏移量
int index = fabs(self.collectionView.contentOffset.x / ZHScreenW);
// 根据偏移量来设置pageControl
ZHLog(@"%d", index);
_pageControl.currentPage = index;
}
// 正确
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
ZHLog(@"%f", self.collectionView.contentOffset.x);
// 计算偏移量
int index = fabs(self.collectionView.contentOffset.x / ZHScreenW);
// 根据偏移量来设置pageControl
ZHLog(@"%d", index);
_pageControl.currentPage = index;
}
4.TableView当Count为0时,分割线不隐藏
_myTbaleView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
5.In App Purchase 上架前几个小时崩溃
因为Apple还没有将环境切换过来,所以等几个小时就可以了。(sandBox->formal)
6.循环发生按钮点击View被重复利用
if (_count.isSelected) {
_label.layer.borderColor = [UIColor colorWithHexString:ZH_THEME_COLOR].CGColor;
_label.textColor = [UIColor colorWithHexString:ZH_THEME_COLOR];
} else {
_label.layer.borderColor = [UIColor colorWithHexString:ZH_FONT_LIGHT_COLOR].CGColor;
_label.textColor = [UIColor colorWithHexString:ZH_FONT_LIGHT_COLOR];
}
ZHLog(@"%@", _count.value);
if ([_count.value isEqualToString:@"-1"]) {
_label.hidden = YES;
_textField.hidden = NO;
} else {
_label.hidden = NO;
_textField.hidden = YES;
}
7.MJExtend怎么转化都转化不成Model
mj_keyValuesArrayWithObjectArray
mj_objectArrayWithKeyValuesArray
8.push/present VC的时候直接到VC的ViewDidLoad方法
ZHHomeLiveDtoModel *dtoModel = [ZHHomeLiveDtoModel mj_objectWithKeyValues:arr[indexPath.row]];
UC_Rose_audienceliveVC *vc = [[UC_Rose_audienceliveVC alloc] init];
vc.view.backgroundColor = [UIColor redColor];
vc.roomModel = dtoModel;
vc.name = dtoModel.tagName;
[self presentViewController:vc animated:YES completion:nil];
在给VC的Model赋值之前,就给VC的backgroundColor赋值,所以会先执行ViewDidLoad里面的代码,所以给Model赋值之前,ViewDidLoad的方法已经得到执行,所以Model的赋值是失败的。
9.@"NSLocalizedDescription" : @"无法连接到 iTunes Store"
```
1.就是因为财务信息,没有填写,所以造成的错误。(协议、税务和银行业务都需要完善)
2.出现这种情况的时候,验证是否是这个原因,去查看products的信息
```
10.reason: 'couldn't find a common superview for > and >
原因是:按钮虽然还在页面上,但是没有添加,约束会出现不明问题
11.因为代码里面布局使用约束进行布局,在更改的时候frame已经不起作用,所以在animation动画里面更改的时候需要控制的也是约束条件,更改frame已经不起作用了
CGRect rect = self.chooseView.frame;
rect.origin.x = self.view.bounds.size.width / 2;
[UIView animateWithDuration:0.3 animations:^{
self.chooseView.frame = rect;
}];
[self.chooseView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.mas_left).offset(self.view.bounds.size.width/2);
}];