gpt4 book ai didi

ios - 获取 iPhone X (10) ios 11 的屏幕尺寸(每条扫描线)(以像素为单位)

转载 作者:行者123 更新时间:2023-11-29 00:10:50 24 4
gpt4 key购买 nike

考虑到 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;
}

Scanline A vs B vs C

具有有用详细信息的相关问题:Detect if the device is iPhone X

最佳答案

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

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

如果您将 View 与布局边距对齐,系统应该注意将您的 View 放在可见区域。

如果您想准确地找出凹口在哪里,您可以通过创建一个采用全屏边界的 View 来凭经验计算它,并对每个坐标进行 HitTest ,检查它是否是“可触摸的”。将坐标收集到某种数组中,然后使用它们以备将来引用。

例如:

    @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

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

关于ios - 获取 iPhone X (10) ios 11 的屏幕尺寸(每条扫描线)(以像素为单位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46510228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com