Iphone 在webView中获得联系
我在Iphone 在webView中获得联系,iphone,uiwebview,Iphone,Uiwebview,我在UIViewController上添加UIWebView,然后在同一ViewController上添加另一个UIViewController,然后我想接触UIWebView我有一个UIWebView作为UIViewController视图的子视图。我的解决方案(制表符手势)是: MyUIViewController正在通过UIgestureRecognitizerDelegate协议实现以下方法(只需重新运行YES): 你必须加上手势 在.h文件中第一次设置委托 -(void)ViewDi
UIViewController
上添加UIWebView
,然后在同一ViewController
上添加另一个UIViewController
,然后我想接触UIWebView我有一个UIWebView
作为UIViewController
视图的子视图。我的解决方案(制表符手势)是:
MyUIViewController
正在通过UIgestureRecognitizerDelegate
协议实现以下方法(只需重新运行YES):
你必须加上手势
在.h文件中第一次设置委托
-(void)ViewDidLoad
{
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(HandleGesture:)];
gesture.delegate=self;
gesture.numberOfTapsRequired = 1;
[YourWebview addGestureRecognizer:gesture];
}
-(void)HandleGesture:(UITapGestureRecognizer *)sender
{
if (gesture.state == UIGestureRecognizerStateEnded)
{
}
if (gesture.state == UIGestureRecognizerStateBegan)
{
// You can write here any action
}
}
- (BOOL)gestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// test if our control subview is on-screen
if ([touch.view isKindOfClass:[UIWebView class]]) {
// You can handle any thing
return YES;
}return NO; // handle the touch
}
要识别UIWebview
,UIScrollview
的触摸事件,您可以使用手势。不要忘记在.h文件中添加UIgestureRecognitizerDelegate
UITapGestureRecognizer *single = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneTap)];
single.numberOfTapsRequired = 1;
single.delegate = self;
[webview addGestureRecognizer:single];
-(void)oneTap{
NSLog(@"single");
}
请注意,手势识别器的触摸是指向视图的,而不是基于页面的。因此,如果你想让你的应用程序响应网页上的某个特定项目,不管它被滚动或缩放到哪里,你最好使用URL方案向你的应用程序发送信号
-(void)ViewDidLoad
{
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(HandleGesture:)];
gesture.delegate=self;
gesture.numberOfTapsRequired = 1;
[YourWebview addGestureRecognizer:gesture];
}
-(void)HandleGesture:(UITapGestureRecognizer *)sender
{
if (gesture.state == UIGestureRecognizerStateEnded)
{
}
if (gesture.state == UIGestureRecognizerStateBegan)
{
// You can write here any action
}
}
- (BOOL)gestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// test if our control subview is on-screen
if ([touch.view isKindOfClass:[UIWebView class]]) {
// You can handle any thing
return YES;
}return NO; // handle the touch
}
UITapGestureRecognizer *single = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneTap)];
single.numberOfTapsRequired = 1;
single.delegate = self;
[webview addGestureRecognizer:single];
-(void)oneTap{
NSLog(@"single");
}