0

セットアップ:タッチイベントに応答するために必要な2つのビューがあり、それらは互いに重ねられています。ビュー1はビュー2の上にあります。ビュー2はUIWebViewです。ビュー1は、タッチイベントをキャプチャするためにサブクラス化されています。

私の問題は、最初のレスポンダーであるビュー1のイベントハンドラー内からUIWebViewイベントハンドラー(touchesBegan:およびtouchesEnded :)を呼び出そうとしても、何も起こらないことです。ただし、ビュー1をuserInteractionEnabled = NOに設定すると、タッチはそのビューを通過し、2番目のビューによって適切に処理されます。

タッチイベントに2つのビューを応答させる方法についてのアイデアはありますか?残念ながら、2番目のビューはUIWebViewであるため、別のメソッドなどではなく、実際にイベントハンドラーを呼び出す必要があります...

アドバイスをよろしくお願いします、ジョエル

4

1 に答える 1

1

これが私の問題の解決策です。あらゆる種類のUIViewで動作しています!誰かがこのコードを改善したい場合

catchUIEventTypeMotion default: ...

このコードがお役に立てば幸いです。

PJ.

CustomWindow.h

#import <Foundation/Foundation.h>

@interface CustomWindow : UIWindow {
}

- (void) sendEvent:(UIEvent *)event;

@end

CustomWindow.m

#import "CustomWindow.h"

@implementation CustomWindow

- (void) sendEvent:(UIEvent *)event
{       
    switch ([event type])
    {
        case UIEventTypeMotion:
            NSLog(@"UIEventTypeMotion");
            [self catchUIEventTypeMotion: event];
            break;

        case UIEventTypeTouches:
            NSLog(@"UIEventTypeTouches");
            [self catchUIEventTypeTouches: event];
            break;      

        default:
            break;
    }
    /*IMPORTANT*/[super sendEvent:(UIEvent *)event];/*IMPORTANT*/
}

- (void) catchUIEventTypeTouches: (UIEvent *)event
{
    for (UITouch *touch in [event allTouches])
    {
        switch ([touch phase])
        {
            case UITouchPhaseBegan:
                NSLog(@"UITouchPhaseBegan");
                break;

            case UITouchPhaseMoved:
                NSLog(@"UITouchPhaseMoved");
                break;

            case UITouchPhaseEnded:
                NSLog(@"UITouchPhaseEnded");
                break;

            case UITouchPhaseStationary:
                NSLog(@"UITouchPhaseStationary");
                break;

            case UITouchPhaseCancelled:
                NSLog(@"UITouchPhaseCancelled");
                break;

            default:
                NSLog(@"iPhone touched");
                break;
        }
    }
}

- (void) catchUIEventTypeMotion: (UIEvent *)event
{
    switch ([event subtype]) {
        case UIEventSubtypeMotionShake:
            NSLog(@"UIEventSubtypeMotionShake");
            break;

        default:
            NSLog(@"iPhone in movement");
            break;
    }
}

@end

AppDelegate.h

#import <UIKit/UIKit.h>
#import "CustomWindow.h"

@interface AppDelegate : NSObject <UIApplicationDelegate>
{
    CustomWindow *window;
}

@property (nonatomic, retain) IBOutlet CustomWindow *window;

@end
于 2010-05-31T17:58:07.067 に答える