Ios 将ImagePicker从“更改为”;使用照片“;至;保存照片
我的应用程序中有一个部件,用户可以在其中快速拍照并将其保存到相机卷中。我唯一想做的是,在拍摄完照片后,它会用方形裁剪器(我猜就是这样)出现在屏幕上,然后在底部写上“重新拍摄”和“使用照片”。我想让那个使用照片的人说“保存照片”(不管怎么说,它就是这么做的)。有什么办法可以这样做吗? 这是我的密码Ios 将ImagePicker从“更改为”;使用照片“;至;保存照片,ios,camera,uiimagepickercontroller,Ios,Camera,Uiimagepickercontroller,我的应用程序中有一个部件,用户可以在其中快速拍照并将其保存到相机卷中。我唯一想做的是,在拍摄完照片后,它会用方形裁剪器(我猜就是这样)出现在屏幕上,然后在底部写上“重新拍摄”和“使用照片”。我想让那个使用照片的人说“保存照片”(不管怎么说,它就是这么做的)。有什么办法可以这样做吗? 这是我的密码 - (IBAction)takePhoto:(UIButton *)sender { UIImagePickerController *picker = [[UIImagePickerControll
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
UIImageWriteToSavedPhotosAlbum(chosenImage, nil, nil, nil);
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
您可以将“取消”按钮更改为您想要的任何标题:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self changeCancelToAnythingUWantOf:viewController andReplacementString:@"Your Replacement String"];
}
你可以通过递归的方式找到这个
func buttonWithTitle(forView view: UIView, title: String) -> UIButton? {
guard view.subviews.count > 0 else { return nil }
var needButton: UIButton? = nil
for subview in view.subviews {
if subview is UIButton {
let button = subview as! UIButton
if button.titleLabel?.text == title {
return button
}
}
needButton = buttonWithTitle(forView: subview, title: title)
if needButton != nil { return needButton }
}
return needButton
}
第一个swizzling Bundle
private func swizzle(ubundle:bundle.Type){
[(#选择器(bundle.localizedString(forKey:value:table:)),
#选择器(bundle.rd_localizedString(forKey:value:table:))]
.forEach{原件,插入
guard let originalMethod=class_getInstanceMethod(捆绑,原始),
让swizzledMethod=class_getInstanceMethod(bundle,swizzled)else{return}
设didAddMethod=class\u addMethod(
捆
起初的
方法_getImplementation(swizzledMethod),
方法\u getTypeEncoding(swizzledMethod)
)
if-didAddMethod{
类替换方法(
捆
嗖嗖地一声,
方法_getImplementation(原始方法),
方法\获取类型编码(原始方法)
)
}否则{
方法交换实施(原始方法、swizzledMethod)
}
}
}
私有变量hasSwizzled=false
扩展包{
最终公共类函数
doBadSwizzleStuff(){
守卫!哈斯威兹勒索其他人{返回}
hasSwizzled=true
swizzle(自我)
}
@objc内部函数rd_本地化字符串(forKey:String,value:String?,table:String?->String{
设bundle=bundle.main
return bundle.rd_localizedString(forKey:forKey,value:value,table:table)
}
}
第二步为UIImagePickerController创建本地化字符串
下面是我看到的带有键的文件内容(带有标准英文值),它们可以自我解释
卡默劳伊
PhotoLibraryServices.String
PhotoLibrary.strings
PhotosUI.strings
第三,实现本地化类
不,无法更改按钮的标题。是否有解决方法?还有,有没有办法摆脱方形作物之类的东西?只拍摄完整照片?可能使用您自己的相机视图覆盖和“重拍/保存”屏幕,而不是启用
allowsdediting
属性。这不适用于更改“使用照片”按钮文本,因为它不在这些视图中。有什么想法吗?谢谢所以,不要使用默认的摄像头控件,请下载示例代码:(苹果的示例代码可能有你想要的)
func buttonWithTitle(forView view: UIView, title: String) -> UIButton? {
guard view.subviews.count > 0 else { return nil }
var needButton: UIButton? = nil
for subview in view.subviews {
if subview is UIButton {
let button = subview as! UIButton
if button.titleLabel?.text == title {
return button
}
}
needButton = buttonWithTitle(forView: subview, title: title)
if needButton != nil { return needButton }
}
return needButton
}
"PHOTO" = "PHOTO";
"AEAF_LOCK_TEXT" = "AE/AF LOCK";
"API_CANCEL_TITLE" = "Cancel";
"HDR_AUTO" = "Auto";
"HDR_ON" = "On";
"HDR_OFF" = "Off";
"TIMER_OFF_TEXT" = "Off";
"USE_PHOTO" = "Use Photo";
"PHOTOS" = "Photos";
"CAMERA_ROLL" = "Camera roll";
"ALL_SCREENSHOTS" = "Screenshots";
"CANCEL" = "Cancel";
"RETAKE" = "Retake";
"STREAM_SHARED_BY_ME_SUBTITLE" = "From You";
"STREAM_SHARED_BY_SUBTITLE" = "From %@";
"ALBUM_IMAGE_COUNT_FORMAT" = "%@ Photos";
"ALBUM_VIDEO_COUNT_FORMAT" = "%@ Videos";
"1_ALBUM_PHOTO" = "1 Photo";
"1_ALBUM_VIDEO" = "1 Video";
"ALBUM_TWO_TYPES_LABEL_COMMAS" = "%@, %@";
"ALL_PHOTOS_IN_LIBRARY" = "Moments";
"PXUserCollectionsSectionTitle" = "My Albums";
"FULL_PHOTOS_GRID_ZOOM_LEVEL_TITLE" = "Moments";
"NO_PHOTOS_OR_VIDEOS" = "No Photos or Videos";
internal enum L10n {
internal enum CameraUI {
/// AE/AF LOCK
internal static let aeafLockText = L10n.tr("CameraUI", "AEAF_LOCK_TEXT")
/// Cancel
internal static let apiCancelTitle = L10n.tr("CameraUI", "API_CANCEL_TITLE")
/// Auto
internal static let hdrAuto = L10n.tr("CameraUI", "HDR_AUTO")
/// Off
internal static let hdrOff = L10n.tr("CameraUI", "HDR_OFF")
/// On
internal static let hdrOn = L10n.tr("CameraUI", "HDR_ON")
/// PHOTO
internal static let photo = L10n.tr("CameraUI", "PHOTO")
/// Off
internal static let timerOffText = L10n.tr("CameraUI", "TIMER_OFF_TEXT")
/// Use test
internal static let usePhoto = L10n.tr("CameraUI", "USE_PHOTO")
}
// MARK: - Implementation Details
extension L10n {
private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
// swiftlint:disable:next nslocalizedstring_key
let format = NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "")
return String(format: format, locale: Locale.current, arguments: args)
}
}
private final class BundleToken {}