如何允许用户从他的相机胶卷或照片库中选取照片?
我正在制作一个小照片编辑应用程序来娱乐。用户必须从相机胶卷中选择一张照片,然后将其导入进行修改。
这通常是如何运作的?我见过许多应用程序允许使用看起来总是相同的标准控制器。
是否也可以直接访问该库或自定义该控制器的外观?
我应该从哪里开始寻找?
I'm making a little photo editing app for fun. Users must select a photo from their camera roll which will then be imported for modification.
How does this generally work? I have seen many apps allowing this with a standard controller that looks always the same.
Is it also possible to access this library directly or to customize the appearance of that controller?
Where should I start looking?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
最简单的方法是在简单的alertView中使用UIImagePickerController。
例如,您希望某人点击他们的个人资料图片并能够从他们的相机或照片库设置新图像。
然后只需添加委托即可完成。
抱歉,这个例子是快速的,但我希望它仍然有帮助。
编辑:针对 Swift 5 进行了更新。
The easiest way to do this is by using the UIImagePickerController in a simple alertView.
For example, you want someone to tap on their profile picture and be able to set a new image from either their camera or their photo library.
Then simply add the delegate and you're done.
Sorry, this example is in swift but I hope it still helps.
EDIT: Updated for Swift 5.
我开发了一个允许用户选择个人图像的应用程序。我有两个 UIButtons 可以帮助用户选择图片,无论是来自相机还是图库。它是这样的:
你必须实现 UIImagePickerControllerDelegate:
希望它有帮助! ;)
I worked on an application that allows user to select a personal image. I had two UIButtons which could help the user to pick a picture, whether it was from camera or library. It's something like this:
You have to implement the UIImagePickerControllerDelegate:
Hope it helps! ;)
该答案仅与物理设备相关!
访问相机:
访问相机胶卷:
实现 UIImagePickerController 的委托方法:
还有这个:
另请检查有关此的更多信息 链接
This answer relevant on physical device ONLY!
Access Camera:
Access Camera Roll:
Implementing the Delegate Methods of UIImagePickerController:
And This:
Also check for more info on this link
SWIFT 2.0
感谢 William T。这对我的 UITapGestureRecognizer 很有用,
我添加了以下内容,以便在将照片选择到 .Camera 和 .PhotoLibrary 后可以对其进行编辑:
SWIFT 2.0
Thanks to William T. this worked for my on my UITapGestureRecognizer
I added the following to let me edit the photo after selecting it to both the .Camera and .PhotoLibrary:
看看
UIImagePickerController
Take a look at
UIImagePickerController
@WilliamT 的回答对我来说非常有效。这是他的,但已针对 Swift 4 进行了更新,以防有人仍在寻找此内容。
这进入视图控制器类块,其中包含要触发相机/图像选择器的按钮。
这位于您的视图控制器类下方:
@WilliamT 's answer worked really well for me. Here is his, but updated for Swift 4 in case anyone is still looking for this.
This goes into the view controller class block that contains the button that you want to trigger the camera/image picker.
This goes below your View Controller Class:
这是一个示例应用程序和一个包装器,可以像 Facebook 一样为您提供“拍照”或“从库中选择”功能。 https://github.com/fulldecent/FDTake
Here is an example app and a wrapper that gives you the Take Photo or Select from Library just like Facebook does. https://github.com/fulldecent/FDTake