最近遇到的一些问题总结
2016-08-18 17:25
435 查看
最近遇到的一些问题总结:
1. 页面中有横向scrollview,手势与滑动返回冲突,致使滑动返回失效的解决办法
- (void)viewDidAppear:(BOOL)animated{
[superviewDidAppear:animated];
NSArray *gestureArray =self.navigationController.view.gestureRecognizers;
// 当是侧滑手势的时候设置scrollview需要此手势失效即可
for (UIGestureRecognizer *gesturein gestureArray) {
if ([gestureisKindOfClass:[UIScreenEdgePanGestureRecognizerclass]])
{
[self.scrollView.panGestureRecognizerrequireGestureRecognizerToFail:gesture];
break;
}
}
}
2. cell中加入scrollview,触摸手势与cell点击事件代理冲突,致使cell点击无效的解决办法
设置:
scrollView.userInteractionEnabled =NO;
[self.contentViewaddGestureRecognizer:scrollView.panGestureRecognizer];
3. 单个页面的导航栏变红,并且不影响其他页面的解决办法:在willAppear中设为红色,WillDisappear在重设回来
- (void)viewWillAppear:(BOOL)animated{
[superviewWillAppear:animated];
self.navigationController.navigationBar.barTintColor
= [RMUtilsthemeColor];
[self.navigationController.navigationBarsetTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColorwhiteColor]}];
[[UIApplicationsharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
}
- (void)viewWillDisappear:(BOOL)animated{
[superviewWillDisappear:animated];
self.navigationController.navigationBar.barTintColor
= [UIColor whiteColor];
[self.navigationController.navigationBarsetTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColorblackColor]}];
[[UIApplicationsharedApplication]setStatusBarStyle:UIStatusBarStyleDefault];
}
4. webview返回上一页功能实现:自定义返回按钮,并判断是否可以返回上一个网页
以及自定义返回按钮太靠右的问题解决:
- (void) addLeftBackButtonItem{
UIButton *leftBackButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
leftBackButton.frame =CGRectMake(0,0,44,44);
[leftBackButton setImage:[UIImageimageNamed:@"return_back"]forState:UIControlStateNormal];
[[leftBackButton rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(id
x) {
if ([self.webViewcanGoBack])
{
[self.webViewgoBack];
}else{
[self.navigationControllerpopViewControllerAnimated:YES];
}
}];
UIBarButtonItem *leftButtonItem = [[UIBarButtonItemalloc]initWithCustomView:leftBackButton];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItemalloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nilaction:nil];
negativeSpacer.width = -15;
self.navigationItem.leftBarButtonItems = [NSArrayarrayWithObjects:negativeSpacer,
leftButtonItem,nil];
}
5. tableview滚动到顶部的功能实现
方法一:当作scrollview处理,设置偏移量:
[self.homeTableViewsetContentOffset:CGPointMake(0,0)animated:Y
d097
ES];
方法二:通过tableview的方法滚动到指定cell的指定位置来处理:
[self.homeTableViewscrollToRowAtIndexPath:[NSIndexPathindexPathForRow:0inSection:0]atScrollPosition:UITableViewScrollPositionTopanimated:NO];
6. tableview设置style为UITableViewStyleGrouped后,出现tableview上面位置有段空白区域的bug处理:设置tableHeaderView高度为0.1。
_goodsShelfTableView.tableHeaderView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,kScreenWidth,0.1f)];
7. 设置navigationBar隐藏时,或者一些其他情况容易出现页头会有一段空白区域,这是因为系统会根据所在界面的status bar,navigationbar,与tabor的高度,自动调整scrollview的inset
,所以解决办法为取消系统自适应,
if ([selfrespondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)])
{
self.automaticallyAdjustsScrollViewInsets =NO;
}
8. 设置webview不可滚动
- (void)disableBounce {
for (id subviewinself.webView.subviews){
if ([[subviewclass]isSubclassOfClass: [UIScrollViewclass]]){
((UIScrollView *)subview).bounces =NO;
}
}
}
9. 加载HTML字符串,并根据文本信息适配高度(完美适配高度)
- (void)webViewDidFinishLoad:(UIWebView *)webView{
NSInteger webViewHeight = [[webViewstringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] integerValue];
//再次设置WebView高度(点)
[webView setHeight:webViewHeight];
}
获取webview的URL和标题
NSString*currentURL=[webViewstringByEvaluatingJavaScriptFromString:@"document.location.href"];
NSString*title=[webviewstringByEvaluatingJavaScriptFromString:@"document.title"];
10. tableview刷新某一条
一个section刷新:
NSIndexSet *indexSet=[[NSIndexSetalloc]initWithIndex:2];
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
一个cell刷新:
NSIndexPath *indexPath=[NSIndexPathindexPathForRow:3inSection:0];
[tableView reloadRowsAtIndexPaths:[NSArrayarrayWithObjects:indexPath,nil]
withRowAnimation:UITableViewRowAnimationNone];
1. 页面中有横向scrollview,手势与滑动返回冲突,致使滑动返回失效的解决办法
- (void)viewDidAppear:(BOOL)animated{
[superviewDidAppear:animated];
NSArray *gestureArray =self.navigationController.view.gestureRecognizers;
// 当是侧滑手势的时候设置scrollview需要此手势失效即可
for (UIGestureRecognizer *gesturein gestureArray) {
if ([gestureisKindOfClass:[UIScreenEdgePanGestureRecognizerclass]])
{
[self.scrollView.panGestureRecognizerrequireGestureRecognizerToFail:gesture];
break;
}
}
}
2. cell中加入scrollview,触摸手势与cell点击事件代理冲突,致使cell点击无效的解决办法
设置:
scrollView.userInteractionEnabled =NO;
[self.contentViewaddGestureRecognizer:scrollView.panGestureRecognizer];
3. 单个页面的导航栏变红,并且不影响其他页面的解决办法:在willAppear中设为红色,WillDisappear在重设回来
- (void)viewWillAppear:(BOOL)animated{
[superviewWillAppear:animated];
self.navigationController.navigationBar.barTintColor
= [RMUtilsthemeColor];
[self.navigationController.navigationBarsetTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColorwhiteColor]}];
[[UIApplicationsharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
}
- (void)viewWillDisappear:(BOOL)animated{
[superviewWillDisappear:animated];
self.navigationController.navigationBar.barTintColor
= [UIColor whiteColor];
[self.navigationController.navigationBarsetTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColorblackColor]}];
[[UIApplicationsharedApplication]setStatusBarStyle:UIStatusBarStyleDefault];
}
4. webview返回上一页功能实现:自定义返回按钮,并判断是否可以返回上一个网页
以及自定义返回按钮太靠右的问题解决:
- (void) addLeftBackButtonItem{
UIButton *leftBackButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
leftBackButton.frame =CGRectMake(0,0,44,44);
[leftBackButton setImage:[UIImageimageNamed:@"return_back"]forState:UIControlStateNormal];
[[leftBackButton rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(id
x) {
if ([self.webViewcanGoBack])
{
[self.webViewgoBack];
}else{
[self.navigationControllerpopViewControllerAnimated:YES];
}
}];
UIBarButtonItem *leftButtonItem = [[UIBarButtonItemalloc]initWithCustomView:leftBackButton];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItemalloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nilaction:nil];
negativeSpacer.width = -15;
self.navigationItem.leftBarButtonItems = [NSArrayarrayWithObjects:negativeSpacer,
leftButtonItem,nil];
}
5. tableview滚动到顶部的功能实现
方法一:当作scrollview处理,设置偏移量:
[self.homeTableViewsetContentOffset:CGPointMake(0,0)animated:Y
d097
ES];
方法二:通过tableview的方法滚动到指定cell的指定位置来处理:
[self.homeTableViewscrollToRowAtIndexPath:[NSIndexPathindexPathForRow:0inSection:0]atScrollPosition:UITableViewScrollPositionTopanimated:NO];
6. tableview设置style为UITableViewStyleGrouped后,出现tableview上面位置有段空白区域的bug处理:设置tableHeaderView高度为0.1。
_goodsShelfTableView.tableHeaderView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,kScreenWidth,0.1f)];
7. 设置navigationBar隐藏时,或者一些其他情况容易出现页头会有一段空白区域,这是因为系统会根据所在界面的status bar,navigationbar,与tabor的高度,自动调整scrollview的inset
,所以解决办法为取消系统自适应,
if ([selfrespondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)])
{
self.automaticallyAdjustsScrollViewInsets =NO;
}
8. 设置webview不可滚动
- (void)disableBounce {
for (id subviewinself.webView.subviews){
if ([[subviewclass]isSubclassOfClass: [UIScrollViewclass]]){
((UIScrollView *)subview).bounces =NO;
}
}
}
9. 加载HTML字符串,并根据文本信息适配高度(完美适配高度)
- (void)webViewDidFinishLoad:(UIWebView *)webView{
NSInteger webViewHeight = [[webViewstringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] integerValue];
//再次设置WebView高度(点)
[webView setHeight:webViewHeight];
}
获取webview的URL和标题
NSString*currentURL=[webViewstringByEvaluatingJavaScriptFromString:@"document.location.href"];
NSString*title=[webviewstringByEvaluatingJavaScriptFromString:@"document.title"];
10. tableview刷新某一条
一个section刷新:
NSIndexSet *indexSet=[[NSIndexSetalloc]initWithIndex:2];
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
一个cell刷新:
NSIndexPath *indexPath=[NSIndexPathindexPathForRow:3inSection:0];
[tableView reloadRowsAtIndexPaths:[NSArrayarrayWithObjects:indexPath,nil]
withRowAnimation:UITableViewRowAnimationNone];
相关文章推荐
- 最近工作中遇到ElasticSearch一些问题总结
- 最近做项目遇到的一些问题总结
- 最近工作中遇到ElasticSearch一些问题总结
- 最近在ArcGIS Engine开发中关于调用gp工具过程出现COM 组件的调用返回了错误 HRESULT E_FAIL 错误的解决方法 和 学习oracle中遇到的一些问题总结
- 最近遇到不少客户提出关于PP账户名字需要更改,如何更改的问题。因此在此做个简单的总结,希望能帮到一些朋友!
- APICloud框架——总结一下最近开发APP遇到的一些问题 (三)
- APICloud框架——总结一下最近开发APP遇到的一些问题 (二)
- 最近遇到的一些小问题总结
- 最近遇到的一些问题总结
- 对最近遇到的一些BT问题总结
- 最近使用Qt遇到的一些小问题解决办法总结
- 总结一下最近面试遇到的一些问题吧
- APICloud框架——总结一下最近开发APP遇到的一些问题
- 最近使用XML过程中一些问题的总结
- WTL学习过程中遇到的一些问题总结
- 最近用了IE6下的滤镜,遇到的几个问题总结:
- 开发CRM中遇到的一些问题总结
- 来点入门级的:最近遇到的一些小问题及经验
- 最近遇到的一些问题及发现
- 最近要做个项目,遇到一些关于ansys问题,看看兄弟们能否帮我解决?