考虑到 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;
}
有帮助细节的相关问题:检测设备是否为 iPhone X