iPad在景观中开始仅在768x768内获得触摸



从肖像开始时,它的工作正常很好,当您从肖像到景观和返回时也可以工作。

从景观开始时,它不起作用。但是,当您从景观旋转到肖像和返回时,它就起作用。

在景观启动模式下,屏幕在屏幕坐标大于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

最新更新