0

Considering that iPhone X Notch has smooth curves (no rectangle around notch), How to find if a pixel (x,y) on captured screenshot is part of draw buffer covered by the notch (vs actual display buffer) on iPhone X?

I am trying to log start X and end Y (pixel) position for actual pixels drawn for each of the horizontal scan lines when iPhone X is in landscape mode.

Is there a way to use inbuilt api to get this information? [[UIScreen mainScreen] nativeBounds] won't suffice in this case.

Hardcoding values or proving an image mask to detect it is possible. I am wondering if there is a more robust way to find width in pixel for scan line A/B/C in attached pic.

// 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

Related question with helpful details: Detect if the device is iPhone X

rmaddy
  • 314,917
  • 42
  • 532
  • 579
lal
  • 7,410
  • 7
  • 34
  • 45
  • Are you asking "how to get the notch " in the iphone-x? – Avba Oct 01 '17 at 09:08
  • Hi @AvnerBarr added details to question. Essentially looking for a way to detect the width for each of the scanline programmatically while avoiding any pixel that falls under "notch". – lal Oct 01 '17 at 09:21

1 Answers1

1

You can reference the documentation here which has some nice images

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

If you align your views to layout margins the system should take care of putting your views in visible areas.

If you want to figure out exactly where the notch is you can empirically calculate it by creating a view taking the full screen bounds, and doing a hit hit test for each coordinate , checking if it is "touchable". Collect the coordinates to some sort of array and then use them for future reference.

For instance something like:

    @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

Notice that it isn't tested and you may need to raise the window level above the status bar or else it may be "underneath" and not respond to touches

Avba
  • 14,822
  • 20
  • 92
  • 192
  • 1
    just saw this reference as well which might assist you https://useyourloaf.com/blog/supporting-iphone-x/ – Avba Oct 01 '17 at 11:37