jas*_*son 7 objective-c ipad uiswipegesturerecognizer
我有一个UIViewController,里面有3个UIWebView.我以编程方式向我的webViews添加了向左滑动.现在我可以刷卡,但只需3页然后再重复一次.我想增加我的currentPage并将其添加到我的webView3,但我不知道该怎么做.
你能给我一些提示吗?我真的有这方面的问题!
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"test view");
NSURL *url = [NSURL fileURLWithPath:[ [ NSBundle mainBundle ] pathForResource: @"Name/Name1" ofType:@"html" ]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView2 loadRequest:request];
[webView2 bringToFront];
NSURL *url = [NSURL fileURLWithPath:[ [ NSBundle mainBundle ] pathForResource:
@"Name/Name2" ofType:@"html" ]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView3 loadRequest:request];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(swipeLeftAction:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.delegate = self;
[self.view addGestureRecognizer:swipeLeft];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer
*)otherGestureRecognizer
{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
currentPage是一个整数,在开头它是0.我的问题是我应该如何将我的currentPage添加到webView3,以便当我滑动它增加我的页面?
- (void)swipeLeftAction:(id)ignored
{
NSLog(@"Swipe Left");
UIWebView *temp = webView2 ;
webView2 = webView3;
webView3 = webView;
webView = temp;
[webView2 bringToFront];
currentPage++;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
****编辑:**
此当前页面未连接到任何webView,如何在webView中获得此增加?**
根据这篇文章中的信息(Does UIGestureRecognizer work on a UIWebView?),看起来手势识别器和 webview 并不总是能够很好地协同工作,原因是 webview 自己的手势识别器。也许最好的方法是在 webview 中添加链接,当触摸时使用您自己的方案来增加 currentPage
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( [[[inRequest URL] absoluteString] hasPrefix:@"mySchemeIncrementPage:"] ) {
currentPage++;
NSLog(@"CURRENT PAGE COUNT: %i", currentPage);
return NO;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
241 次 |
| 最近记录: |