iOS中给webView添加手势返回的问题
2016-02-20 21:10
417 查看
在IOS开发中,给webView添加一个轻扫手势,就可以返回上一个网页.
上代码
#import "CKCenterMenuVC.h"
@interface
CKCenterMenuVC ()
@property(nonatomic,strong)
NSURL *url;
@property(nonatomic,strong)
UIWebView *web;
@end
@implementation CKCenterMenuVC
- (void)viewDidLoad {
[super
viewDidLoad];
//登录状态
if ([Context
logined]) {
[self loadWebView];
};
self.title =
@"社区";
//创建webView
UIWebView *web = [[UIWebView
alloc]
initWithFrame:self.view.bounds];
web.scalesPageToFit =
YES;
web.height = kIphoneHeight -
108;
//添加一个轻扫手势
UISwipeGestureRecognizer *swip = [[UISwipeGestureRecognizer
alloc]
initWithTarget:self
action:@selector(back)] ;
[web addGestureRecognizer:swip];
self.web = web;
[self.view
addSubview:web];
}
/**
* 返回上一个网页
*/
- (void)back
{
[self.web
goBack];
}
/**
* 加载一个网页
*/
- (void)loadWebView{
//当前登录用户
MDUser *user = [Context
sharedInstance].modianUser;
NSDictionary *parameters =
@{@"user_id":user.userId};
//请求数据
[HttpTool postWithPath:@"/v20/main/moxi_index"
params:parameters
success:^(id json) {
MyLog(@"%@",json);
if ([json[@"status"]
intValue] == 0) {
NSDictionary *urlDict = json[@"data"];
NSString *urlStr= urlDict[@"url"];
self.url = [NSURL
URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:self.url];
[self.web
loadRequest:request];
}
} failure:^(NSError *error) {
MyLog(@"%@",error);
}];
}
@end
上代码
#import "CKCenterMenuVC.h"
@interface
CKCenterMenuVC ()
@property(nonatomic,strong)
NSURL *url;
@property(nonatomic,strong)
UIWebView *web;
@end
@implementation CKCenterMenuVC
- (void)viewDidLoad {
[super
viewDidLoad];
//登录状态
if ([Context
logined]) {
[self loadWebView];
};
self.title =
@"社区";
//创建webView
UIWebView *web = [[UIWebView
alloc]
initWithFrame:self.view.bounds];
web.scalesPageToFit =
YES;
web.height = kIphoneHeight -
108;
//添加一个轻扫手势
UISwipeGestureRecognizer *swip = [[UISwipeGestureRecognizer
alloc]
initWithTarget:self
action:@selector(back)] ;
[web addGestureRecognizer:swip];
self.web = web;
[self.view
addSubview:web];
}
/**
* 返回上一个网页
*/
- (void)back
{
[self.web
goBack];
}
/**
* 加载一个网页
*/
- (void)loadWebView{
//当前登录用户
MDUser *user = [Context
sharedInstance].modianUser;
NSDictionary *parameters =
@{@"user_id":user.userId};
//请求数据
[HttpTool postWithPath:@"/v20/main/moxi_index"
params:parameters
success:^(id json) {
MyLog(@"%@",json);
if ([json[@"status"]
intValue] == 0) {
NSDictionary *urlDict = json[@"data"];
NSString *urlStr= urlDict[@"url"];
self.url = [NSURL
URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:self.url];
[self.web
loadRequest:request];
}
} failure:^(NSError *error) {
MyLog(@"%@",error);
}];
}
@end
相关文章推荐
- ios中运行时学习笔记
- 微信公开课系列视频 观后感
- IOS开发中关于automaticallyAdjustsScrollViewInsets属性
- Android各种权限
- Android沉浸式通知栏的一个开源库SystemBarTint简单使用
- Android_ListView_有Header或Footer时onItemClick里的position的问题
- 实现类似微信Viewpager-Fragment的惰性加载,lazy-loading
- iOS中一个tableView中显示两种cell的问题
- 自己动手丰衣足食之移动端日期选择插件(强烈推荐)
- Android 中SD卡是否存在以及剩余空间的大小查询
- iOS 导出ipa包时四个选项的意义
- Android动画框架(二)----属性动画
- Android的IPC机制(二)——AIDL实现原理简析
- Swift笔记 使用CocoaPods来添加开源库
- android audio buffer 分析
- 解决Android Studio Fetching Android SDK component information失败问题
- android audio分析
- Swift笔记 使用SwiftData和sqlite的环境设置
- android audio 音量设置分析
- 在Eclipse添加Android兼容包( v4、v7 appcompat )