简体   繁体   中英

Camera Overlay not in the center

I am trying to add an overlay to this UIImagePickerController instance but the result is the overlay off center.

I have created a simple red square (300x300 pt) to exemplify the problem and serve as an overlay and added that to the camera overlay, using this:

  CGRect bounds = [[UIScreen mainScreen] bounds];

  UIView *containerOverlay = [[UIView alloc] initWithFrame:bounds];

  UIImage *overlay = [UIImage imageNamed:@"red"];
  UIImageView *overlayView = [[UIImageView alloc] initWithImage:overlay];
  CGFloat midX = CGRectGetMidX(bounds);
  CGFloat midY = CGRectGetMidY(bounds);

  CGPoint center = CGPointMake(midX, midY);
  overlayView.center = center;
  [containerOverlay addSubview:overlayView];


 [_camera setCameraOverlayView:containerOverlay];

this is what is shown on the live preview... completely off the vertical center.

在此处输入图片说明

amazingly, when I take the picture and iOS shows me the picture already taken, the overlay is magically centered...

在此处输入图片说明

How do I center the overlay on the live camera?

Well the overlay is y-centered to the screen bounds right?

在此处输入图片说明

Which is what you are doing here:

CGFloat midX = CGRectGetMidX(bounds);
CGFloat midY = CGRectGetMidY(bounds);

If you want the overlay aligned to the actual image rect you need to offset the bottom black bar (it's not the same height as the top black bar).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM