0

考虑到 iPhone X Notch 具有平滑的曲线(在凹槽周围没有矩形),如何确定捕获的屏幕截图上的像素 (x,y) 是否是 iPhone X 上的凹槽(与实际显示缓冲区)覆盖的绘制缓冲区的一部分?

当 iPhone X 处于横向模式时,我正在尝试记录为每个水平扫描线绘制的实际像素的开始 X 和结束 Y(像素)位置。

有没有办法使用内置的 api 来获取这些信息?[[UIScreen mainScreen] nativeBounds]在这种情况下是不够的。

硬编码值或证明图像掩码来检测它是可能的。我想知道是否有更强大的方法来查找附件图片中扫描线 A/B/C 的像素宽度。

// For a given scan-line for a given Y = any-value between 0 & window.screen.height (Landscape orientation)
+ (CGPoint)printScanlineForY:(NSUInteger )y {
    // what goes here?
    ... 

    // Case 1: expected for non-notch scan-line, return CGPointMake(0, screen-width)

    // Case 2: expected for notch affected scan-line, return (non-0, screen-width)  
    // non-0 as determined by notch draw curve.
}

// Returning nativeBounds CGRect would return larger bounding box for entire screen.
// Output on iPhone X simulator: Native Screen Bounds: {{0, 0}, {1125, 2436}}
+ (CGRect)printScreenBounds {
    CGRect bounds = [[UIScreen mainScreen] nativeBounds];
    NSLog(@"Native Screen Bounds: %@", NSStringFromCGRect(bounds));
    return bounds;
}

扫描线 A vs B vs C

有帮助细节的相关问题:检测设备是否为 iPhone X

4

1 回答 1

1

你可以参考这里的文档,里面有一些漂亮的图片

https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/

如果您将视图与布局边距对齐,则系统应注意将视图放置在可见区域中。

如果您想确切地确定缺口在哪里,您可以通过创建一个采用全屏边界的视图来凭经验计算它,并对每个坐标进行命中测试,检查它是否“可触摸”。将坐标收集到某种数组中,然后将它们用于将来参考。

例如:

    @implementation FindNotch

    - (nullable UIView *)hitTest:(CGPoint)point withEvent:(nullable UIEvent *)event;   // recursively calls -pointInside:withEvent:. point is in the receiver's coordinate system
    {
      UIView *hitView = [super hitTest...];
      if (view == null) { ... } // the notch isn't "touchable"
    }
    @end

    FindNotch *notch = [FindNotch alloc] initWithFrame:[UIScreen mainScreen].bound];
  static UIWindow *window; window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds;]
window.windowLevel = UIWindowLevelStatusBar + 1; // make sure the view is above anything else in the notch area. Might require some tweaking

请注意,它未经测试,您可能需要将窗口级别提高到状态栏上方,否则它可能在“下方”并且不响应触摸

于 2017-10-01T09:33:22.727 回答