Ios 截取WkWebView中的滑动边缘
在webview中,当客户端向左/向右滑动时,它应该调用我的代码(即,从Ios 截取WkWebView中的滑动边缘,ios,objective-c,cocoa-touch,uigesturerecognizer,wkwebview,Ios,Objective C,Cocoa Touch,Uigesturerecognizer,Wkwebview,在webview中,当客户端向左/向右滑动时,它应该调用我的代码(即,从HandlerRightedGegesture打印日志)。这不会发生。为什么呢 这是我到目前为止的代码 #import "ViewController.h" @import App; @interface ViewController () @end @interface ViewController () <UIGestureRecognizerDelegate> { CGFloat _center
HandlerRightedGegesture
打印日志)。这不会发生。为什么呢
这是我到目前为止的代码
#import "ViewController.h"
@import App;
@interface ViewController ()
@end
@interface ViewController () <UIGestureRecognizerDelegate> {
CGFloat _centerX;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// track swipe left/right gestures
UIScreenEdgePanGestureRecognizer *leftEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftEdgeGesture:)];
leftEdgeGesture.edges = UIRectEdgeLeft;
leftEdgeGesture.delegate = self;
[self.view addGestureRecognizer:leftEdgeGesture];
UIScreenEdgePanGestureRecognizer *rightEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightEdgeGesture:)];
rightEdgeGesture.edges = UIRectEdgeRight;
rightEdgeGesture.delegate = self;
[self.view addGestureRecognizer:rightEdgeGesture];
// launch the webview
self.productURL = @"http://localhost:3010";
NSURL *url = [NSURL URLWithString:self.productURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
_webView = [[WKWebView alloc] initWithFrame:self.view.frame];
//_webView.allowsBackForwardNavigationGestures = TRUE;
[_webView loadRequest:request];
_webView.frame = CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
// add the gesture trackers to the webview
[_webView addGestureRecognizer:rightEdgeGesture];
[_webView addGestureRecognizer:leftEdgeGesture];
[self.view addSubview:_webView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)handleLeftEdgeGesture:(UIScreenEdgePanGestureRecognizer *)gesture {
// Get the current view we are touching
if(UIGestureRecognizerStateBegan == gesture.state ||
UIGestureRecognizerStateChanged == gesture.state) {
// CGPoint translation = [gesture translationInView:gesture.view];
NSLog(@"DEBUG: gesture left complete %@", nil);
} else { // cancel, fail, or ended
// reset
NSLog(@"DEBUG: gesture left reset %@", nil);
}
}
- (void)handleRightEdgeGesture:(UIScreenEdgePanGestureRecognizer *)gesture {
// Get the current view we are touching
if(UIGestureRecognizerStateBegan == gesture.state ||
UIGestureRecognizerStateChanged == gesture.state) {
// CGPoint translation = [gesture translationInView:gesture.view];
// gensture complete?
NSLog(@"DEBUG: gesture right complete %@", nil);
} else { // cancel, fail, or ended
// reset
NSLog(@"DEBUG: gesture right reset %@", nil);
}
}
@end
#导入“ViewController.h”
@导入应用程序;
@界面视图控制器()
@结束
@界面视图控制器(){
CGFloat\u centerX;
}
@结束
@实现视图控制器
-(无效)viewDidLoad{
[超级视图下载];
//轨迹向左/向右滑动手势
UIScreenedGepAgestureRecognitor*LeftedGeesture=[[UIScreenedGepAgestureRecognitor alloc]initWithTarget:self-action:@selector(HandleLeftedGe手势:)];
LeftedgeSture.edges=UIDirectedgeLeft;
leftedgegestrue.delegate=self;
[self.view addgesturecognizer:leftEdgeGesture];
UIScreenedGepAgestureRecognizer*RightedGeesture=[[UIScreenedGepAgestureRecognizer alloc]initWithTarget:self action:@selector(HandlerRightedGeesture:)];
RightedgeSture.edges=UIDirectedgeRight;
Rightedgegstrue.delegate=自我;
[self.view addgesturecognizer:Rightedgegestrue];
//启动webview
self.productURL=@”http://localhost:3010";
NSURL*url=[NSURL URLWithString:self.productURL];
NSURLRequest*request=[nsurlRequestRequestWithURL:url];
_webView=[[WKWebView alloc]initWithFrame:self.view.frame];
//_webView.AllowsBackforwardNavigationPigests=TRUE;
[_webviewloadrequest:request];
_webView.frame=CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y,self.view.frame.size.width,self.view.frame.size.height);
//将手势跟踪器添加到webview
[\u webView AddGestureRecognitor:Rightedgegstrue];
[_WebViewAddgestureRecognitor:leftEdgeGesture];
[self.view addSubview:_webView];
}
-(无效)未收到记忆警告{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(void)Handleftedge手势:(UIScreenedgepangestureRecognitor*)手势{
//获取我们正在接触的当前视图
if(UIgestureRecognitizerStateStarted==手势.state||
UIgestureRecognitzerStateChanged==手势.state){
//CGPoint translation=[手势翻译视图:手势.视图];
NSLog(@“调试:手势左完成%@”,无);
}else{//取消、失败或结束
//重置
NSLog(@“调试:手势左复位%@”,无);
}
}
-(无效)HandlerRightedGegesture:(UIScreenedGePangestureRecognitor*)手势{
//获取我们正在接触的当前视图
if(UIgestureRecognitizerStateStarted==手势.state||
UIgestureRecognitzerStateChanged==手势.state){
//CGPoint translation=[手势翻译视图:手势.视图];
//完整的基因?
NSLog(@“调试:手势右完成%@”,无);
}else{//取消、失败或结束
//重置
NSLog(@“调试:手势右复位%@”,无);
}
}
@结束
添加“多手势”支持似乎可以让它工作,尽管我宁愿完全取消webkitview手势控制,但我不知道如何操作
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
您应该能够使用属性
禁用放大手势和导航手势放大率
和允许返回向前地航行在WKWebView上分别显示手势
再加上
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
应该按你的要求去做