プレーンな JavaScript を使用して、iPad の Safari ですべてのデフォルト ジェスチャを無効にする方法。event.preventDefault();
すべてのイベントで使用しようとしましたが、機能していません。私は Safari でアプリを実行し、すべてのデフォルトのタッチ イベント (ジェスチャー) を無効にして、独自のものでオーバーライドしたいと考えています。また、オプション prevent_default を持つ人気のあるライブラリー hammer.js を使用してみましたが、機能しません。
2348 次
2 に答える
3
スクロールの防止:
document.ontouchmove = function(event){
event.preventDefault();}
タップ防止:
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
于 2013-02-05T12:54:24.290 に答える
0
あなたの質問は十分に明確ではないと思います(変更してください)。UIWebView を備えた iOS アプリがあり、その UIWebView でのすべてのマウス操作を無効にしたいということですか? もしそうなら、実際には次のような方法でスクロールを無効にする必要があります:
<script type="text/javascript">
touchMove = function(event) {
event.preventDefault();
}
</script>
UIWebViews は、タッチとゲストを下のビューに渡しません。ネイティブ コードでタッチを処理する場合は、ワイルドカード GestureRecognizer を UIWebView に追加するだけです。以下に、使用できるヘルパー クラスを示します。以下を呼び出して、UIWebView でそれを使用できます。
[[WildcardGestureRecognizerForwarder alloc] initWithController:self andView:self.webview];
プロジェクトで、次のコードを使用して WildcardGestureRecognizerForwarder.h を追加します。
#import <Foundation/Foundation.h>
typedef void (^TouchesEventBlock)(NSSet * touches, UIEvent * event);
@interface WildcardGestureRecognizerForwarder : UIGestureRecognizer
@property(nonatomic,assign) UIView *forwardFrom;
@property(nonatomic,assign) UIViewController *forwardTo;
-(void) initWithController:(UIViewController*)theViewController andView:(UIView*)theView;
@end
また、次のコードを含むファイル WildcardGestureRecognizerForwarder.m を追加します。
#import "WildcardGestureRecognizerForwarder.h"
@implementation WildcardGestureRecognizerForwarder
-(id) init {
if (self = [super init])
{
self.cancelsTouchesInView = NO;
}
return self;
}
-(void) initWithController:(id)theViewController andView:(UIView*)theView {
if ([self init]) {
self.forwardFrom = theView;
self.forwardTo = theViewController;
[theView addGestureRecognizer:self];
self.delegate = theViewController;
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if(self.forwardTo)
[self.forwardTo touchesBegan:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
if(self.forwardTo)
[self.forwardTo touchesCancelled:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if(self.forwardTo)
[self.forwardTo touchesEnded:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if(self.forwardTo)
[self.forwardTo touchesMoved:touches withEvent:event];
}
- (void)reset
{
}
- (void)ignoreTouch:(UITouch *)touch forEvent:(UIEvent *)event
{
}
- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer
{
return NO;
}
- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer
{
return NO;
}
@end
于 2013-02-05T09:09:42.750 に答える