我可以从照片库中选择并显示图像,但我的目标是能够将选择的图像或文件路径保存到核心数据,以便在选择保存的记录时也会显示图像.
我有CoreData工作,我能够从CoreData显示文本很好,它只是图像阻止我.
@IBAction func addPic(sender: AnyObject) {
pickerController.delegate = self
pickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
// 2
self.presentViewController(pickerController, animated: true, completion: nil)
// Displays image
func imagePickerController(picker: UIImagePickerController!,didFinishPickingMediaWithInfo info: NSDictionary!){
image.image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismissViewControllerAnimated(true, completion: nil)
Run Code Online (Sandbox Code Playgroud) 我相信这是一个常见的问题,许多答案不再适用,很多只是部分,如果你在iOS7下,你的iPad应用程序只是Landscape,但你想使用UIImagePickerControllerwith source UIImagePickerControllerSourceTypePhotoLibrary或UIImagePickerControllerSourceTypeCamera.
如何设置正确,所以它100%工作?并且您没有获得混合方向并避免错误"支持的方向与应用程序没有共同的方向,并shouldAutorotate返回YES".
cocoa-touch uiimagepickercontroller ipad uiinterfaceorientation ios
从iOS 9和Xcode 7开始,我无法再在iPad(设备和模拟器)上实现UIImagePickerController.以下代码适用于iPad,但仅适用于iOS 9.使用iOS 9+时,显示的图像(在UIImagePickerController被取消后)是所选图像的错误版本.没有重新调整大小或裁剪最终图像只是原始图像的右上角?? 另外一个问题 - 如果imagePicker.allowsEditing = false,你无法从PhotoLibrary中选择图像?
@IBAction func photoButton(sender: AnyObject) {
imagePicker.allowsEditing = true
imagePicker.sourceType = .PhotoLibrary
self.presentViewController(imagePicker, animated: false, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
self.imageView.image = pickedImage
dismissViewControllerAnimated(true, completion: { () -> Void in
})
}
Run Code Online (Sandbox Code Playgroud)
下面是UIImagePickerController中显示的选定图像的示例.(注意所选图像如何呈现非常小而不像以前那样呈现屏幕的全尺寸/宽度)
在UIImagePickerController中选择使用按钮后,最终图像仅在原始图像的右上角.我在做错了什么或是在iOS 9上破坏了UIImagePickerController?
我使用ViewController中的以下代码调出相机:
- (void)viewDidLoad {
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.sourceType = UIImagePickerControllerCameraDeviceFront;
self.imgPicker.delegate = self;
}
- (IBAction)grabCamera {
[self presentModalViewController:self.imgPicker animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能让相机默认使用iPhone4的前置摄像头而不是后置摄像头?我试过DeviceFront无济于事.
此外,如何在按下grabCamera后在此相机的顶部添加子视图(半尺寸)?如果我在我的MainWindow.xib中有这个子视图我在说完presentModalViewController代码之后尝试说addSubview但它没有用...我需要创建一个NSTimer并在完全呈现相机显示后加载addSubview或者我需要使用别的东西(类似于CSS中的z-index)第二个问题的答案是imgPicker.cameraOverlayView = viewName;
谢谢大家!
我正在努力捕获使用4.0返回的图像
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
// MediaType can be kUTTypeImage or kUTTypeMovie. If it's a movie then you
// can get the URL to the actual file itself. This example only looks for images.
//
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
// NSString* videoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
// Try getting the edited image first. If it doesn't exist then you get the
// original image.
//
if (CFStringCompare((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) {
UIImage* picture …Run Code Online (Sandbox Code Playgroud) 我正在创建一个横向模式的应用程序,我正在UIImagePickerController使用iPhone相机拍摄照片,我也希望以横向模式创建它.
但是,正如Apple文档所暗示的UIImagePickerController那样,不支持横向定位,那么我该如何才能获得所需的功能呢?
landscape objective-c uiimagepickercontroller ios uiimageorientation
我在用
UIImagePickerControllerDelegate,
UINavigationControllerDelegate,
UIPopoverControllerDelegate
Run Code Online (Sandbox Code Playgroud)
这些代表从我的画廊或我的相机中选择图像.那么,如何在选择图像后获得图像文件大小?
我想用这个:
let filePath = "your path here"
var fileSize : UInt64 = 0
do {
let attr : NSDictionary? = try NSFileManager.defaultManager().attributesOfItemAtPath(filePath)
if let _attr = attr {
fileSize = _attr.fileSize();
print(fileSize)
}
} catch {
}
Run Code Online (Sandbox Code Playgroud)
但是在这里我需要一条路径,但是如果没有路径,我只能通过图像文件获得?
我添加了UIImagePickerController一个UIViewController.我也指定了UIImagePickerControllerDelegate那个UIViewController.
当我执行以下行时,
myPicker.delegate = self;
Run Code Online (Sandbox Code Playgroud)
Xcode通过以下消息告诉我:
警告:从不兼容的类型'RootViewController'分配id
然后我将UINavigationControllerDelegate协议添加到同一个UIViewController并且错误消息消失了.
所以,我必须双方协议添加到UIViewController时候我加入UIImagePickerController?
如果它UIImagePickerController是UINavigationController文档中所述的子类,那么这不应该是自动的吗?为什么我必须添加其父代理协议而不仅仅是UIImagePickerControllerDelegate协议?
这是一个错误还是我错过了什么?
iphone inheritance delegates uiimagepickercontroller uinavigationcontroller
在我的应用程序中,我需要选择任何视频文件并在应用程序中显示视频文件的URL.
-(void)viewDidLoad{
[super viewDidLoad];
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
self.imgPicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
self.imgPicker.allowsEditing = NO;
[self presentModalViewController:self.imgPicker animated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo{
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
value = 1;
IMAGE_COUNTER = IMAGE_COUNTER + 1;
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ( [mediaType isEqualToString:@"public.movie" ])
{
NSLog(@"Picked a movie at URL %@", [info objectForKey:UIImagePickerControllerMediaURL]);
NSURL *url = [info …Run Code Online (Sandbox Code Playgroud) 在[camera takePicture]相机准备好之前调用时,会发出以下消息:
UIImagePickerController: ignoring request to take picture; camera is not yet ready.
我怎么知道什么时候准备拍照?
[camera isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] 总是返回true,即使它显然没有准备好.
ios ×5
iphone ×4
swift ×4
camera ×2
ipad ×2
objective-c ×2
uiimage ×2
cocoa-touch ×1
core-data ×1
delegates ×1
inheritance ×1
landscape ×1
uiimageview ×1