【问题标题】:Is there a way when you take a picture on iOS7 to not have it flip horizontally using code?有没有办法在iOS7上拍照时不使用代码水平翻转?
【发布时间】:2013-12-10 19:48:20
【问题描述】:

我想知道这是否真的可以做到。我知道我可以翻转 UIImageView,但是 iOS 7 上的相机会在您选择它以显示在 uiimageview 中之前显示水平翻转的图片。有什么办法可以解决这个烦恼吗?如果有请告诉我。这对用户来说可能非常烦人,因为他们可能不知道更好。 编辑:这是我的代码。

        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
    }

    // image picker needs a delegate,
    [imagePickerController setDelegate:self];

    // Place image picker on the screen
    [self presentModalViewController:imagePickerController animated:YES];

【问题讨论】:

  • 我想我可以帮忙,但需要更多详细信息 - 您使用的是 UIImagePickerController 还是创建了自己的相机捕获实例?
  • uiimagepickercontroller 我会更新一些代码

标签: ios objective-c uiimageview camera


【解决方案1】:

根据Apple's UIImagePickerClass Reference,您不能轻松做到这一点:

重要提示:UIImagePickerController 类仅支持纵向模式。此类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改,但有一个例外。您可以将自定义视图分配给 cameraOverlayView 属性,并使用该视图来显示附加信息或管理相机界面和代码之间的交互。

这意味着,如果您想弄乱方向,您将需要创建自己的相机控制器并自行处理。查看this stack overflow question and answer 了解更多关于这些方面的信息。编码愉快!

【讨论】:

    【解决方案2】:

    Swift 中的完整工作示例,它回答了本文最初的问题(在 iPhone 5c 上使用 iOS 8.2 测试):

            import UIKit
    
            class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate {
    
             @IBOutlet var myUIImageView: UIImageView!
    
             var myUIImagePickerController: UIImagePickerController!
    
             override func viewDidLoad() {
                 super.viewDidLoad()
             }
    
             override func viewWillAppear(animated: Bool) {
                 println("viewWillAppear(animated: Bool) method called.")
                 super.viewWillAppear(animated)
                 NSNotificationCenter.defaultCenter().removeObserver(self)
             }
    
             override func viewWillDisappear(animated: Bool) {
                 println("viewWillDisappear(animated: Bool) method called.")
                 super.viewWillDisappear(animated)
                 NSNotificationCenter.defaultCenter().addObserver(self, selector: "cameraChanged:", name: "AVCaptureDeviceDidStartRunningNotification", object: nil)
             }
    
             /* UIImagePickerControllerDelegate Section */
             func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
                  if(self.myUIImagePickerController.sourceType == UIImagePickerControllerSourceType.Camera) {
                     self.myUIImageView.image = info[UIImagePickerControllerEditedImage] as? UIImage
                  } else {
                     self.myUIImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
                  }
                  self.dismissViewControllerAnimated(true, completion: nil)
             }
    
            func imagePickerControllerDidCancel(picker: UIImagePickerController) {
                self.dismissViewControllerAnimated(true, completion: nil)
            }
    
            /*
            You can choose to use one of the UIResponder methods:
            touchesBegan, touchesMoved, touchesEnded etc, in order to detect the touch
            on the UIImageView.
            */
            override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
                let touch: UITouch? = touches.anyObject() as? UITouch
                if (touch?.view == myUIImageView) {
                    println("myUIImageView has been tapped by the user.")
                    self.takingAPictureUsingTheCamera()
                }
            }
    
            func takingAPictureUsingTheCamera() {
                self.myUIImagePickerController = UIImagePickerController()
                self.myUIImagePickerController.delegate = self // Set the delegate
                self.myUIImagePickerController.sourceType = UIImagePickerControllerSourceType.Camera
                self.myUIImagePickerController.cameraDevice = UIImagePickerControllerCameraDevice.Front
        //        self.myUIImagePickerController.editing = true
                self.myUIImagePickerController.allowsEditing = true
                self.presentViewController(self.myUIImagePickerController, animated: true, completion: nil)
            }
    
            func cameraChanged(notification: NSNotification) {
                 println("cameraChanged(notification: NSNotification) method called.")
                 self.myUIImagePickerController.cameraViewTransform = CGAffineTransformIdentity
                 if(self.myUIImagePickerController.cameraDevice == UIImagePickerControllerCameraDevice.Front){
                     self.myUIImagePickerController.cameraViewTransform = CGAffineTransformScale(self.myUIImagePickerController.cameraViewTransform, -1, 1)
                 }
            }
           }// End class
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-14
      • 2018-11-01
      • 2022-08-14
      • 2021-07-21
      相关资源
      最近更新 更多