您的位置:首页 > 其它

最近遇到的一些问题总结

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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: