在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