2013-12-20 24 views
0

當我在橫向模式下在iPad上啓動我的通用應用程序時,應用程序無法識別離主屏幕按鈕最近的屏幕側的點擊或手勢。我已經在stackoverflow的每一個類似的問題,試圖達到這個底部,但我不能得到它的工作。iPad應用程序在橫向模式下啓動時不能識別的點擊和手勢

看來,視圖層次結構中的一個視圖是縱向而不是橫向的,但我找不到任何大小不正確的視圖。另外,請注意,在縱向模式下啓動並正確旋轉時,該應用可以正常工作,並可識別旋轉後的所有水龍頭。但是當在橫向上發射時,屏幕的一側總是存在一個「盲區」,無法識別抽頭。

視圖層次是這樣的:

UIWindow (frame: 0, 0, 1024, 768) 
UINavigationController 
    UIViewController 
    UIView (frame: 0, 0, 1024, 768) 
     GLView (frame: 0, 0, 1024, 768) 

我檢查了框架和範圍的意見,將clipsToBounds = YES和改變他們的背景顏色,看看他們沒有被正確地奠定了,但他們是全部按照預期佔據整個屏幕(1024x768)。

我已經子類UIWindow並重寫sendEvent:方法,並且當我點擊屏幕左側的死區時,它不會被調用。這是否表明問題可能出在哪裏?

這裏是我的應用程序代理在其中創建窗口:

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

    // Create the main window 
    CGRect windowFrame = [[UIScreen mainScreen] bounds]; 
    if (application.statusBarOrientation == UIInterfaceOrientationLandscapeLeft || application.statusBarOrientation == UIInterfaceOrientationLandscapeRight) { 
     windowFrame = CGRectMake(0, 0, windowFrame.size.height, windowFrame.size.width); 
    } 
    window_ = [[MyUIWindow alloc] initWithFrame:windowFrame]; 

    navController_ = [[BFNavigationController alloc] init]; 
    navController_.navigationBarHidden = YES; 

    // for rotation and other messages 
    [[CCDirector sharedDirector] setDelegate:navController_]; 

    // set the Navigation Controller as the root view controller 
    [window_ setRootViewController:navController_]; 

    bfViewController_ = [[BFViewController alloc] init]; 
    [navController_ pushViewController:bfViewController_ animated:NO]; 

    // make main window visible 
    [window_ makeKeyAndVisible]; 

    return YES; 
} 

這是UIViewController的viewDidLoad方法,其中的UIView配置:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIWindow *mainWindow = (UIWindow*)[UIApplication sharedApplication].windows.firstObject; 
    self.view.frame = mainWindow.bounds; 

    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; 
    self.view.autoresizesSubviews = YES; 
    self.view.clipsToBounds = YES; 

    [self initCocos2D]; 

} 

而這裏的GLView創建其中:

- (void)initCocos2D { 

    UIWindow *window = [[[UIApplication sharedApplication] windows] firstObject]; 
    CCDirector *director = (CCDirectorIOS*) [CCDirector sharedDirector]; 

    CCGLView *glView = [CCGLView viewWithFrame:[window bounds] 
            pixelFormat:kEAGLColorFormatRGB565 
            depthFormat:0 
          preserveBackbuffer:NO 
            sharegroup:nil 
           multiSampling:NO 
           numberOfSamples:0]; 

    glView.clipsToBounds = YES; 
    [glView setMultipleTouchEnabled:YES]; 

    director.wantsFullScreenLayout = YES; 

    // set FPS at 60 
    [director setAnimationInterval:1.0/60]; 

    // attach the openglView to the director 
    [director setView:glView]; 

    // 2D projection 
    [director setProjection:kCCDirectorProjection2D]; 

    // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices 
    if(! [director enableRetinaDisplay:YES]) 
     CCLOG(@"Retina Display Not supported"); 

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images 
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565 
    // You can change this setting at any time. 
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888]; 

    // Assume that PVR images have premultiplied alpha 
    [CCTexture2D PVRImagesHavePremultipliedAlpha:YES]; 

    [self.view insertSubview:glView atIndex:0]; 

    [[CCDirector sharedDirector] startAnimation]; 
} 

手勢識別器被添加到glView中並由cocos2D遊戲層:

UIPanGestureRecognizer *panGestureRecognizer = [[[UIPanGestureRecognizer alloc] initWithTarget:layer action:@selector(handlePan:)] autorelease]; 
    [[CCDirector sharedDirector].view addGestureRecognizer:panGestureRecognizer]; 

    UITapGestureRecognizer *tapGestureRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:layer action:@selector(handleTap:)] autorelease]; 
    [[CCDirector sharedDirector].view addGestureRecognizer:tapGestureRecognizer]; 

    UIPinchGestureRecognizer *pinchGestureRecognizer = [[[UIPinchGestureRecognizer alloc] initWithTarget:layer action:@selector(handlePinch:)] autorelease]; 
    [[CCDirector sharedDirector].view addGestureRecognizer:pinchGestureRecognizer]; 

這讓我瘋狂;任何幫助將非常感激。

+0

節目,你怎麼加的姿態,以及如何處理觸摸 –

+0

更多的細節嗎? –

+0

添加代碼以顯示UIWindow和視圖如何初始化。 – stackunderflow

回答

-1

我可以用下面的步驟來解決這個問題:

[UIScreen mainscreen].bounds作爲它的框架,這將永遠是肖像創建的UIWindow。我以前根據不正確的方向更改窗口邊界。

使用當前狀態欄方向來確定縱向/橫向並相應地設置最低級別的UIView幀。 (即1024×768的景觀和768x1024的肖像)

設置glView的框架,以其父的UIView的邊界,而不是窗口的邊界

相關問題