iOS 项目中常见问题及解决办法
2014-07-17 00:16
162 查看
最近做项目遇到一些小问题,虽然不严重但是也是必须要清楚how to finish的,如:
键盘管理,与tableView结合使用,聊天界面的键盘管理
#pragma mark - 监听键盘高度改变事件
- (void)keyboardWillShow:(NSNotification *)notification {
// get keyboard frame
CGRect frameOfKeyboard = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
UIView * window = [[[UIApplication sharedApplication] delegate] window];
frameOfKeyboard = [self.view convertRect:frameOfKeyboard fromView:window];
CGRect frameOfInputView = self.toolBar.frame;
frameOfInputView.origin.y = frameOfKeyboard.origin.y - frameOfInputView.size.height;
UIEdgeInsets insets = UIEdgeInsetsZero;
insets.bottom = frameOfKeyboard.size.height;
// get infomation of keyboard animation
NSTimeInterval duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationOptions options = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue];
[UIView animateWithDuration:duration
delay:0
options:options
animations:^{
self.toolBar.frame = frameOfInputView;
self.chatTableView.contentInset = insets;
} completion:nil];
[self scrollToBottom];
//self.isInputPadShow = YES;
[self.chooseImage setHidden:YES];
self.isKeyboardShow = YES;
}
给聊天信息背景切图的时候,总是切不出想要的效果来,最后发现原来是@2x的背景图,用的时候直接把图片名包括@2x都写进来了,去掉@2x 即可
在代码中给控件设置文字颜色或背景颜色时 使用
如何让UIButton的title左对齐,
【iOS开发】判断NSString中的字符是否为中文的正确方法
在Unicode编码的NSString中,遍历字符串中的汉字呢
这样的确可以判断大多数中文符号,但是少数字符比如句号“。”在unichar存储的16进制值要小于0x4e00,查了很多资料
键盘管理,与tableView结合使用,聊天界面的键盘管理
#pragma mark - 监听键盘高度改变事件
- (void)keyboardWillShow:(NSNotification *)notification {
// get keyboard frame
CGRect frameOfKeyboard = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
UIView * window = [[[UIApplication sharedApplication] delegate] window];
frameOfKeyboard = [self.view convertRect:frameOfKeyboard fromView:window];
CGRect frameOfInputView = self.toolBar.frame;
frameOfInputView.origin.y = frameOfKeyboard.origin.y - frameOfInputView.size.height;
UIEdgeInsets insets = UIEdgeInsetsZero;
insets.bottom = frameOfKeyboard.size.height;
// get infomation of keyboard animation
NSTimeInterval duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationOptions options = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue];
[UIView animateWithDuration:duration
delay:0
options:options
animations:^{
self.toolBar.frame = frameOfInputView;
self.chatTableView.contentInset = insets;
} completion:nil];
[self scrollToBottom];
//self.isInputPadShow = YES;
[self.chooseImage setHidden:YES];
self.isKeyboardShow = YES;
}
-(void)scrollToBottom{ if (self.sumChat.count > 0) { NSIndexPath *path = [NSIndexPath indexPathForRow:self.sumChat.count-1 inSection:0]; [self.chatTableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionBottom animated:YES]; } }
给聊天信息背景切图的时候,总是切不出想要的效果来,最后发现原来是@2x的背景图,用的时候直接把图片名包括@2x都写进来了,去掉@2x 即可
UIImage* trackImage = [UIImage imageNamed:@"icon_audio_gray_img.png"]; trackImage = [trackImage resizableImageWithCapInsets:UIEdgeInsetsMake(2, 12, 2, 2) resizingMode:UIImageResizingModeStretch];
在代码中给控件设置文字颜色或背景颜色时 使用
[UIColor colorWithRed: green: blue:];这个方法,如果直接写255 之类的值显示的效果肯定不是我们想要的,或者无法显示,此时应该是用rgb的值除以255,如119.0/255 ,注意是浮点型
如何让UIButton的title左对齐,
【iOS开发】判断NSString中的字符是否为中文的正确方法
在Unicode编码的NSString中,遍历字符串中的汉字呢
unichar ch = [string characterAtIndex:i]; if (0x4e00 < ch && ch < 0x9fff) { return true; }
这样的确可以判断大多数中文符号,但是少数字符比如句号“。”在unichar存储的16进制值要小于0x4e00,查了很多资料
#define IS_CH_SYMBOL(chr) ((int)(chr)>127)
NSMutableDictionary * params = [NSMutableDictionary dictionary]; [params setObject:self.firstNameLabel.text forKey:@"firstName"]; [params setObject:self.lastNameLabel.text forKey:@"lastName"]; [params setObject:self.telLabel.text forKey:@"phoneNum"]; [params setObject:self.emailLabel.text forKey:@"email"]; [params setObject:self.feedbackContent.text forKey:@"commons"]; NSString * postURL = [params cdvjk_JSONString]; NSLog(@"postURL:%@",postURL); NSString * urlStr = FEEDBACK; NSLog(@"url%@",urlStr); NSURL * url = [NSURL URLWithString:urlStr]; NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:url]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:[postURL dataUsingEncoding:NSUTF8StringEncoding]]; [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; NSURLResponse * urlResponse = [[NSURLResponse alloc] init]; NSError * error = nil; NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error]; NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
相关文章推荐
- COCOS2D-X项目在XCODE没有IOS Simulator,无法仿真的解决办法
- flask初学项目常见问题及解决办法
- iOS常见问题及解决办法积累
- iOS项目被拒原因总结及解决办法
- 写一个之前遇到的问题,遇到ios项目中包含idfa的解决办法
- iOS 曾经上传照片到项目中,但是后面删除了,在真机调试中报错的解决办法
- Android Studio项目构建时遇到的常见问题及解决办法
- 在ios 项目中出现 linker command failed with exit code 1 (use -v to see invocation)解决办法
- 项目笔记--- iOS开发IPV6 被拒解决办法预防
- xcode ios项目出现编译问题的解决办法
- Xcode中iOS项目目标变为Mac的解决办法
- iOS 项目中包含多个 FFMPEG 方法冲突的通用解决办法。
- iOS 项目中包含多个 FFMPEG 方法冲突的通用解决办法。
- iOS开发百度地图常见问题及解决办法
- 页面控制常见问题及解决办法
- VS.NET在生成安装和部署项目时收到"不可恢复的致命错误"的解决办法
- 试图运行项目时出错:无法在web服务器上启动项目得解决办法
- 试图运行项目时出错:无法在web服务器上启动项目得解决办法
- 试图运行项目时出错:无法在web服务器上启动项目得解决办法
- 页面控制常见问题及解决办法