您的位置:首页 > 移动开发

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