1

OK、前の質問は詳細ではなかったと思います。詳細をお伝えしています。

完全なソース コードを投稿する前に、質問する必要があります。以前の iOS SDK では機能していました。現在の xcode のバージョンは 3.2.5 です

1 つのコメント: 次のコードを iPad シミュレーターに対して実行すると、すべてのタッチが呼び出されます。そのため、iPhone シミュレーターと実際のデバイスが問題に応答しないのは非常に奇妙です。

main.m

#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
    [pool release];
    return retVal;
}

AppDelegate.h

#import <UIKit/UIKit.h>
@class GLView;

@interface AppDelegate : NSObject <UIApplicationDelegate> 
{
    UIWindow*   mp_window;
    GLView*     mp_viewController;
}

@end

AppDelegate.mm

#import "AppDelegate.h"
#import "GLView.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    CGRect screenBounds = [[UIScreen mainScreen] bounds];

    mp_window = [[UIWindow alloc] initWithFrame: screenBounds];
    mp_viewController = [[GLView alloc] initWithFrame: screenBounds];   


    [mp_window addSubview: mp_viewController];
    [mp_window makeKeyAndVisible];

    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{}

- (void)applicationDidBecomeActive:(UIApplication *)application
{}

- (void)applicationWillTerminate:(UIApplication *)application
{}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Handle any background procedures not related to animation here.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Handle any foreground procedures not related to animation here.
}

- (void)dealloc
{
    [mp_viewController release];
    [mp_window release];

    [super dealloc];
}

@end

GLView.h

#import <OpenGLES/EAGL.h>
#import <QuartzCore/QuartzCore.h>

@interface GLView : UIView <UIAccelerometerDelegate>
{
@private
    EAGLContext*        mp_context;
}

- (void) gameLoop;

- (void) drawView: (float) interpolation;

- (void)touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
- (void)touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
- (void)touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;

- (void)accelerometer: (UIAccelerometer *) accelerometer 
        didAccelerate: (UIAcceleration *) acceleration;

@end

GLView.mm

#import "GLView.h"
#import <OpenGLES/ES2/gl.h>

@implementation GLView

+ (Class) layerClass
{
    return [CAEAGLLayer class];
}

- (id) initWithFrame: (CGRect) frame
{
    if (self = [super initWithFrame: frame]) 
    {
        CAEAGLLayer* eaglLayer = (CAEAGLLayer*) super.layer; 
        eaglLayer.opaque = YES; 

        EAGLRenderingAPI api = kEAGLRenderingAPIOpenGLES1;
        mp_context = [[EAGLContext alloc] initWithAPI: api];

        if (!mp_context || ![EAGLContext setCurrentContext: mp_context]) 
        {
            [self release];
            return nil;
        }

        [mp_context renderbufferStorage: GL_RENDERBUFFER 
                           fromDrawable: eaglLayer];

        //TODO: to setup the size of frame for render
        //////

        //acc
        [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(0.1f)];
        [[UIAccelerometer sharedAccelerometer] setDelegate:self];

        //multi - touch
        [self setUserInteractionEnabled:YES];
        [self setMultipleTouchEnabled:YES];


        [self performSelectorOnMainThread:@selector(gameLoop) 
                               withObject:nil waitUntilDone:NO];
    }

    return self;
}

- (void) gameLoop
{   
    while(1)
    {
            //Get all touches
        while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 
                     0.002f, 
                     TRUE) == kCFRunLoopRunHandledSource);
            //render scene
            [drawView 1.0f];
    }
}

- (void) drawView: (float) interpolation
{
    //TODO: adding render image here
    //NSLog(@"Render: %f", interpolation);
    [mp_context presentRenderbuffer: GL_RENDERBUFFER];
}

- (void) dealloc
{

    if ([EAGLContext currentContext] == mp_context)
        [EAGLContext setCurrentContext: nil];


    [mp_context release]; 
    //TODO: relese all objects here
    [super dealloc];    
}

- (void)touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event 
{
    int hash;
    CGPoint points;
    for(UITouch * touch in touches)
    {
        hash = [touch hash];
        points = [touch locationInView: self];
        NSLog(@"Touch Began: %d, %f, %f", hash, points.x, points.y);
    }
}


- (void)touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event 
{
    int hash;
    CGPoint points;
    for(UITouch * touch in touches)
    {
        hash = [touch hash];
        points = [touch locationInView: self];
        NSLog(@"Touch Moved: %d, %f, %f", hash, points.x, points.y);
    }
}


- (void)touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event 
{
    int hash;
    CGPoint points;
    for(UITouch * touch in touches)
    {
        hash = [touch hash];
        points = [touch locationInView: self];
        NSLog(@"Touch Ended: %d, %f, %f", hash, points.x, points.y);
    }
}

- (void) accelerometer: (UIAccelerometer *) accelerometer 
         didAccelerate: (UIAcceleration *) acceleration 
{
    NSLog(@"Accelerometer: (%f, %f, %f)", 
          acceleration.x, 
          acceleration.y, 
          acceleration.z );
}

@end

これは単なるテストケースです。私の主な関心事は、なぜ新しい SDK で touches が呼び出されないのかということです。NSTimer やその他のタイマーを使用する必要があるとは言わないでください。新しい SDK をインストールする前に作業を行いました。それ以外に、そのソースコードに問題がある人がいるかどうか疑問に思っています。

ありがとう、メンフィス

4

1 に答える 1

0

あなたの問題が何であるかは確かにわかりません。ただし、View Controller がないことに注意してください。UIApplicationDelegate サブクラスには mp_viewController メンバーがありますが、これは UIViewController ではなく UIView です。これが問題の原因である可能性があります。

ビューに関連付けられた UIViewController を追加し、それをアプリケーション デリゲートの rootViewController プロパティに割り当てることをお勧めします。

于 2010-12-14T19:51:57.613 に答える