【问题标题】:Problem with the camera相机有问题
【发布时间】:2010-08-12 08:40:13
【问题描述】:

我目前正在开发一个应用程序,它使用 UIImagePickerController 来使用内置相机拍照。

我不想做的是在 UIImagePickerController 的底部栏上为用户提供一个开关,以便能够在前后摄像头之间切换(当然如果可用的话)。我知道如何确定是否有前置摄像头,但是如何在底栏上显示这样的开关?

感谢您的帮助!

【问题讨论】:

    标签: iphone objective-c image camera


    【解决方案1】:

    .h 文件 @property(nonatomic) UIImagePickerControllerCameraDevice cameraDevice;

    cameraButtonPressed 方法打开后置摄像头。 changeCam 方法在后置和前置摄像头之间切换。

    .m 文件

    -(无效)cameraButtonPressed { overLay=[[UIView alloc]initWithFrame:CGRectMake(0,0, 320, 480)]; UIImage *CameraClickImg=[UIImage imageNamed:@"capture.png"]; UIButton *captureBtn=[UIButton buttonWithType:UIButtonTypeCustom]; [captureBtn setFrame:CGRectMake(35,440, 240,40)]; [captureBtn addTarget:self action:@selector(captureImage) forControlEvents:UIControlEventTouchUpInside]; [captureBtn setImage:CameraClickImg forState:UIControlStateNormal]; UIButton *changeBtn=[UIButton buttonWithType:UIButtonTypeCustom]; [changeBtn setFrame:CGRectMake(250,30, 40,40)]; [changeBtn addTarget:self action:@selector(changeCam) forControlEvents:UIControlEventTouchUpInside]; [changeBtn setImage:CameraClickImg forState:UIControlStateNormal]; 选择器 = [[UIImagePickerController alloc] init]; 选择器.delegate = self; 选择器.allowsEditing = NO; picker.sourceType = UIImagePickerControllerSourceTypeCamera; 选择器.showsCameraControls=否; picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff; 选择器.cameraOverlayView=overLay; [自我presentModalViewController:选择器动画:YES]; [覆盖 addSubview:captureBtn]; [覆盖 addSubview:changeBtn]; [选择器发布]; [self.view addSubview:activityIndi​​cator]; } -(void)captureImage { [选择器拍照]; } -(无效)changeCam { 如果(picker.cameraDevice==UIImagePickerControllerCameraDeviceRear) picker.cameraDevice=UIImagePickerControllerCameraDeviceFront; 别的 picker.cameraDevice=UIImagePickerControllerCameraDeviceRear; }

    【讨论】:

      【解决方案2】:

      UIImagePickerControllershowsCameraControls 设置为YES 或使用cameraOverlayView 提供您自己的控件。

      要在前后摄像头之间切换,请使用UIImagePickerControllercameraDevice 属性。

      【讨论】:

      • 问题的引用:“...但是我怎样才能显示这样的开关...”
      • 问题的引用:“......能够在前后摄像头之间切换”,所以他的意思是他如何显示一个开关在切换时显示前置摄像头上
      • @Nuker 请澄清您的问题。
      • 我想要的是:我希望 UIImagePicker 在底栏上有一个开关,当 UIImagePicker 显示时,用户可以在前后摄像头之间切换。因此,当用户按下“拍照”按钮时,我想向他展示常见的 UIImagePicker 并且用户可以在 UIImagePicker 中选择他是想用前置摄像头还是后置摄像头拍照。我希望这能澄清我的问题。
      • @Nuker 你想知道如何展示控件(在我的回答中描述)或者如何在你自己的代码中切换前后摄像头吗?
      猜你喜欢
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-05
      • 1970-01-01
      • 2016-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多