如何在 Swift 中使用 UIImagePickerController 旋转cameraOverlayView上的图像
我有以下代码,用于为 UIImagePickerController 创建cameraOverlayView:(
使用 Xcode 13.2.1 )
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.camera)
{
print("device have a camera")
let imagePicker = UIImagePickerController()
imagePicker.delegate = self as UIImagePickerControllerDelegate & UINavigationControllerDelegate
imagePicker.sourceType = UIImagePickerController.SourceType.camera
let imageOverlayName = getimageOverlayNameByPosicaoIdFoto(posicaoIdFoto) // just return a string with an Image name
let mainView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height))
let imageOverlay = UIImage(named: imageOverlayName)
let imageViewOverlay = UIImageView(image: imageOverlay!)
let numberToAllowTopControlsToAppear:CGFloat = 18
let positionY = self.view.frame.size.height / numberToAllowTopControlsToAppear
let numberToAllowBottomControlsToAppear:CGFloat = 5.5
let bottomBarHeightSize = self.view.frame.size.height - ( self.view.frame.size.height / numberToAllowBottomControlsToAppear )
imageViewOverlay.frame = CGRect(x: 0, y: positionY, width: self.view.frame.size.width, height: bottomBarHeightSize)
mainView.isUserInteractionEnabled = false
mainView.addSubview(imageViewOverlay)
imagePicker.cameraOverlayView = mainView
self.present(imagePicker, animated: true, completion: nil)
}
此代码运行良好,但图像固定在屏幕中。 如果用户更改设备方向(通过旋转设备),如何旋转叠加中使用的图像?
I have the following code that I use to create an cameraOverlayView for a UIImagePickerController:
( using Xcode 13.2.1 )
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.camera)
{
print("device have a camera")
let imagePicker = UIImagePickerController()
imagePicker.delegate = self as UIImagePickerControllerDelegate & UINavigationControllerDelegate
imagePicker.sourceType = UIImagePickerController.SourceType.camera
let imageOverlayName = getimageOverlayNameByPosicaoIdFoto(posicaoIdFoto) // just return a string with an Image name
let mainView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height))
let imageOverlay = UIImage(named: imageOverlayName)
let imageViewOverlay = UIImageView(image: imageOverlay!)
let numberToAllowTopControlsToAppear:CGFloat = 18
let positionY = self.view.frame.size.height / numberToAllowTopControlsToAppear
let numberToAllowBottomControlsToAppear:CGFloat = 5.5
let bottomBarHeightSize = self.view.frame.size.height - ( self.view.frame.size.height / numberToAllowBottomControlsToAppear )
imageViewOverlay.frame = CGRect(x: 0, y: positionY, width: self.view.frame.size.width, height: bottomBarHeightSize)
mainView.isUserInteractionEnabled = false
mainView.addSubview(imageViewOverlay)
imagePicker.cameraOverlayView = mainView
self.present(imagePicker, animated: true, completion: nil)
}
This code works perfectly, but the image is fixed in the screen.
If the user change the device orientation(by rotating the device), how can I rotate the image used in the overlay ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是使用以下代码来跟踪用户是否旋转设备
I just use the following code to track if the user rotate the device