1 、ios navigationcontroller 滑動傳回
滑動傳回是navigationcontroller預設傳回按鈕自帶的功能,如果傳回按鈕自定義該功能失效,
解決的辦法有兩個:
①
self.navigationItem.backBarButtonItem = [[UIBarButtonItemalloc]initWithCustomView:button];//這個方法用不了
隻能用
self.navigationItem.backBarButtonItem =
[ [UIBarButtonItem alloc]initWithTitle: style: target: action:]
選擇範圍較小,
②
UIButton*button = [UIButtonbuttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(0,0,40,40)];
[button setTitle:@"傳回"forState:UIControlStateHighlighted];
[button setTitle:@"傳回"forState:UIControlStateNormal];
[button addTarget:selfaction:@selector(back)forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem*bar = [[UIBarButtonItemalloc]initWithCustomView:button];
self.navigationItem.leftBarButtonItem = bar;
但是要在push之後加上
if ([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
}
③第二種方法有漏洞(連續多次快速滑動的時候容易崩潰),下面是最新的方法
在主viewconroller中添加:
self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
還有:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if (self.navigationController.viewControllers.count == 1)//關閉主界面的右滑傳回
{
return NO;
}
else
{
return YES;
}
}
最後一個方法感謝:http://www.tuicool.com/articles/vMfAVv
2、webview加載html圖檔自适應螢幕寬度
在用webview加載html的時候如果碰到html中有圖檔的時候,如果不對html做一下處理的話,會發現,加載出來的圖檔有些是對
螢幕不會自己适配的,這個時候處理的時候有兩種方法,
①對webview做下處理,
self.mWebView.scalesPageToFit =YES;
這個方法不完善,圖檔是會适配螢幕,但是字型會變小,
②寫一個webview的拓展類
裡面對html文本用js或者css做一下處理,添加一個一個head
[content appendString:@"<html>"];
[content appendString:@"<head>"];
[content appendString:@"<meta charset=\"utf-8\">"];
[content appendString:@"<meta id=\"viewport\" name=\"viewport\" content=\"width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=false\" />"];
[content appendString:@"<meta name=\"apple-mobile-web-app-capable\" content=\"yes\" />"];
[content appendString:@"<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black\" />"];
[content appendString:@"<meta name=\"black\" name=\"apple-mobile-web-app-status-bar-style\" />"];
[content appendString:@"<style>img{width:100%;}</style>"];
[content appendString:@"<style>table{width:100%;}</style>"];
[content appendString:@"<title>webview</title>"];
這個處理的比較完美,也可以加在html的尾部,但是沒有放在頭部靈活, 最後一個方法