ios - iPad 在 Landscape 中启动仅接收 768x768 内的触摸

标签 ios ipad touch landscape screen-orientation

从纵向开始时它工作得很好,当你从纵向旋转到横向并返回时也能正常工作。

它在横向启动时不起作用。但是,当您从横向旋转到纵向并返回时,它会起作用。

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

代码中发生的事情是,我使用状态栏方向来确定原始方向并手动旋转每个 View 。 View 显示正确但未正确接收触摸。

然后当 ipad 开始旋转时我的 Root View Controller 将被调用:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

这将旋转每个 subview 。

根 Controller :

- (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];
    }

}

最佳答案

好的。所以事实证明,在数十个背景和图层中,有些没有正确旋转到风景/肖像......调试这个问题非常困难......

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

非常有用! 只需在您的代码中使用下面的 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

关于ios - iPad 在 Landscape 中启动仅接收 768x768 内的触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13180946/

相关文章:

ios - iOS 如何处理不同版本的图像?

iphone - 有多个函数调用而不是一个大的函数调用有任何性能增益/损失?

android - 在 Android 中实现一个 slider (SeekBar)

javascript - 当多个触摸靠得太近时,iOS 触摸会卡住吗?

ios - Objective-C - 同时关闭表单和页面表

ios - NSURLConnection(作为 AFNetworking 的一部分)不调用 NSURLConnectionDataDelegate 委托(delegate)

ios - Swift-从随机创建的文档ID(Firestore)中获取字段

ios - 在Light模式下获取PKDrawing的图像

iphone - 付费到免费反射(reflection)时间Appstore

iOS 在给定空间点的情况下找到盒子