본문 바로가기
프로그래밍/iOS

Swipe Gesture with UIWebView

by 백룡화검 2012. 5. 31.

webView에서 마우스액션처럼 뒤로 앞으로 구현!!

 

- (void)viewDidLoad {
    [super viewDidLoad];
 //Swipe Left
 UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftAction:)];
 swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
 //swipeLeft.delegate = self;
 [webView addGestureRecognizer:swipeLeft];
 
 //Swipe Right
 UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction:)];
 swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
 //swipeRight.delegate = self;
 [webView addGestureRecognizer:swipeRight];
 
 webView.delegate = self;
 NSString *homeUrl = @http://www.naver.com;
 
 NSURL *url = [NSURL URLWithString:homeUrl];
 NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
 
 [webView loadRequest:requestObj];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
 return YES;
}

- (void)swipeRightAction:(id)ignored
{
 [webView goForward];
}

- (void)swipeLeftAction:(id)ignored
{
 [webView goBack];
}