·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> ios截屏(代码)

ios截屏(代码)

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

//1.首先在storyboard中拖一些控件,包括UIButton控件,将UIButton控件拖线到控制器中(方法、CutImage)

//2.在CutImage方法中调用NSTimer方法

- (IBAction)CutImage:(UIButton *)sender {

  NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 targer:self  selector:@selector(clipImage) userInfo:nil repeats:NO];

}

//3.调用clipImage方法

-(void)clipImage

{

  //1.创建图形上下为难

  UIGraphicsBeginImageCOntextWithOptions(self.view.bounds.size,NO,0.0);

  //2.调取方法截屏(截取的是全屏)

  [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

  //3.获得当前的图片

  UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

  //4.结束图形上下文

  UIGraphicsEndImgeContext();

   //5.打印数据

   NSData *data =UIImagePNGRePResentation(newImage);

  [data writeToFile:@"/User/apple/DeskTop/new1.png" atomically:YES];

  

}