美文网首页
IOS programming 4th Edition

IOS programming 4th Edition

作者: 旅行和阳光 | 来源:发表于2016-06-20 15:51 被阅读161次

    11.camera
    Gold Challenge
    问题:利用UIImagePickerController 中cameraOverlayView属性。使其在取景视图的正中显示一个十字。
    代码如下:
    //添加照片

    • (IBAction)takePicture:(id)sender {
      UIImagePickerController *imagePicker =
      [[UIImagePickerController alloc] init];

      //如果设备支持相机,就使用拍照模式
      //否则让用户从照片库中选择照片
      if ([UIImagePickerController
      isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
      imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
      imagePicker.showsCameraControls = YES;
      //相机十字显示
      UIView *crosshair = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
      crosshair.backgroundColor = [UIColor clearColor];
      //横线
      UIView *line1=[[UIView alloc]initWithFrame:CGRectMake(0, 29.5, 60, 1)];
      line1.backgroundColor=[UIColor whiteColor];
      [crosshair addSubview:line1];
      //竖线
      UIView *line2=[[UIView alloc]initWithFrame:CGRectMake(29.5, 0, 1, 60)];
      line2.backgroundColor=[UIColor whiteColor];
      [crosshair addSubview:line2];

        crosshair.center = self.view.center;
        imagePicker.cameraOverlayView = crosshair;
      

      }else{
      imagePicker.sourceType =
      UIImagePickerControllerSourceTypePhotoLibrary;

      }
      //可编辑
      imagePicker.allowsEditing = YES;

      imagePicker.delegate = self;

      //以模态的形式显示UIImagePickerController对象
      [self presentViewController:imagePicker animated:YES completion:nil];
      }

    相关文章

      网友评论

          本文标题:IOS programming 4th Edition

          本文链接:https://www.haomeiwen.com/subject/bdottttx.html