Ios iPad横向启动仅接收768x768以内的触摸屏

Ios iPad横向启动仅接收768x768以内的触摸屏,ios,ipad,touch,landscape,screen-orientation,Ios,Ipad,Touch,Landscape,Screen Orientation,从纵向开始时,它工作得非常好,在从纵向旋转到横向和向后旋转时也可以工作 在景观中开始时,它不起作用。但当你从横向旋转到纵向再旋转回来时,它就会起作用 在横向启动模式下,当屏幕坐标大于768时,屏幕不响应任何触摸。 代码中发生的是,我使用状态栏方向来确定原始方向,并手动旋转每个视图。视图显示正确,但触摸不正确 当ipad开始旋转时,我的根视图控制器将被调用: - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInt

从纵向开始时,它工作得非常好,在从纵向旋转到横向和向后旋转时也可以工作

在景观中开始时,它不起作用。但当你从横向旋转到纵向再旋转回来时,它就会起作用

在横向启动模式下,当屏幕坐标大于768时,屏幕不响应任何触摸。

代码中发生的是,我使用状态栏方向来确定原始方向,并手动旋转每个视图。视图显示正确,但触摸不正确

当ipad开始旋转时,我的根视图控制器将被调用:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
它将旋转每个子视图

根控制器:

- (void)loadView {
    self.view = [[UIView alloc]init ]; 
    //initialize child views
    [self willRotateToInterfaceOrientation:0 duration:0];    

}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if ([model isLandscape]) {
        self.view.frame = CGRectMake(0, 0, 1024, 768-80);
    }
    else {
        self.view.frame = CGRectMake(0, 0, 768, 1024-80);
    }
    //rotate child views  
}
我的代码[model isLandscape]工作正常,因此我不需要提供有关其工作原理的详细信息,但下面是代码:

- (bool)isLandscape {
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
        return true;
    else 
        return false;
}

-(id) init
{
    [[NSNotificationCenter defaultCenter] addObserver:self   selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}

- (void)orientationChanged:(NSNotification *)notification
{
    UIInterfaceOrientation curOrientation = [[UIDevice currentDevice] orientation];
    if (curOrientation == UIDeviceOrientationPortrait ||
        curOrientation == UIDeviceOrientationPortraitUpsideDown ||
        curOrientation == UIDeviceOrientationLandscapeLeft ||
        curOrientation == UIDeviceOrientationLandscapeRight)
    {
        orientation = curOrientation;
        ((AppDelegate*)([UIApplication sharedApplication].delegate)).savedOrientationForRestart = orientation;
        NSLog(@"changed");
    }
}

-(void)validateOrientation { //first time when initializing orientation
    UIInterfaceOrientation curOrientation = [[UIDevice currentDevice] orientation];
    if (curOrientation != UIDeviceOrientationPortrait &&
        curOrientation != UIDeviceOrientationPortraitUpsideDown &&
        curOrientation != UIDeviceOrientationLandscapeLeft &&
        curOrientation != UIDeviceOrientationLandscapeRight)
    {
        orientation = [[UIApplication sharedApplication] statusBarOrientation];
    }

}

嗯。因此,在几十个背景和图层中,有些没有正确地旋转到横向/纵向…调试这个问题非常困难

最后,我连接了一个触摸调试器来查看哪些视图正确接收触摸,哪些视图没有

非常有帮助! 只要在代码中使用下面的UIWindow子类而不是UIWindow,就可以了

    #import <UIKit/UIKit.h>
    @interface MyUIWindow : UIWindow {
    }

    -(void)rotate;

    @end

请出示一些代码。如何创建视图?
    #import "MyUIWindow.h"
    @implementation MyUIWindow

    -(id) init{
        self = [super init];
        if(self)
        {
        }
        return self;
    }

    - (void)sendEvent:(UIEvent *)event {
        [super sendEvent:event];
        NSSet *touches = [event allTouches];
        if (touches.count != 1)
            return;
        UITouch *touch = touches.anyObject;    
        UIView * view = touch.view;
        NSLog(NSStringFromClass([touch.view class])); //this prints out touch view
    }


    @end