怎么拍圆屏?

时间:2012-10-22 08:27:16

标签: objective-c ios screenshot

我看过很多关于截图的问题和答案,我知道怎么做,这不是我的问题,这是我的代码:

- (void)takeScreenShot
{
    //UIGraphicsBeginImageContextWithOptions(CGSizeMake(320, 340), YES, 0.);
    UIGraphicsBeginImageContext(CGSizeMake(320, 480));
    [self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}

如何才能拍摄圆形屏幕而不是320x480方框?

2 个答案:

答案 0 :(得分:3)

你可以试试这个:

- (UIImage *)takeRoundedScreenShot:(CGPoint)center
{
  float cornerRadius = self.view.window.layer.cornerRadius;
  CGAffineTransform savedTransform = self.view.window.transform;

  UIGraphicsBeginImageContext(CGSizeMake(320, 320));
  self.view.window.layer.cornerRadius = 160;
  self.view.window.clipsToBounds = YES;
  self.view.window.transform = CGAffineTransformMakeTranslation(-(center.x-160), -(center.y-160));
  [self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
  UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();

  self.view.window.transform = savedTransform;
  self.view.window.layer.cornerRadius = cornerRadius.

  return viewImage;
}

答案 1 :(得分:1)

我认为这不可能,但您可以随时round the corners yourself