I wrote a application that take pictures from PhotoLibray. When I run the app, it succeed, and then I select a picture from the library, and I set the allowEditing property to YES, but when the edit screen shows, no edit tool show, I cannot edit the picture. I used xcode6, the class is UIImagePickerController. Code is below,
- (IBAction)takePicture:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// If the device ahs a camera, take a picture, otherwise,
// just pick from the photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
imagePicker.delegate = self;
// Place image picker on the screen
[self presentViewController:imagePicker animated:YES completion:nil];
}
When the edit screen shows, there are 2 buttons, one is "Cancel" and the other is "choose". I press the left mouse button and drag it, but nothing shows, I can only move the picture and when I release the left mouse, the picture return back to the old place.
Why I cannot edit or crop the picture?
See UIImagePickerController allowsEditing will only allow you to crop image. It does nothing more. If you want to add more editing features you should implement by your self.
I was wrong, I can edit it. I search this using Internet, I can move and scale the picture and choose the picture in the square area, then get the picture after edited.The problem was resolved.
Related
i have tried to get an answer to this question for a while. what i am trying to do is fire the UIImagePickerController and either choose from camera or select from goto library. this part works just fine. then i want to set that image as the button image on top of the button i am using to fire the image picker. in iOS 6 that was working just fine. since iOS 7 the image does not get set as the button image. i have tried many links and read many posts and went through even dev forum with no success in finding an answer. this is the last part of my desperate attempt to find an answer before going to apple technical support. i am hoping someone would be able to help me out. below is the code i am using to set the image to the button after selecting it from UIImagePickerController.
- (IBAction)choosePhoto
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
}
- (IBAction)takePhoto {
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
{
if (imagePicker) {
self.image = [info objectForKey:UIImagePickerControllerEditedImage];
[self.choosePhotoButton setImage:self.image forState:UIControlStateNormal];
} else {
if (picker) {
self.image = [info objectForKey:UIImagePickerControllerEditedImage];
[self.takePhotoButton setImage:self.image forState:UIControlStateNormal];
}
}
[self dismissViewControllerAnimated:YES completion:nil];
imagePicker = nil;
}
currently after selecting either button the image set on it is the tint color of the button as it shows in the screen shot below. the two white squares are the buttons where the picked image should be.
can someone take a look at my code and help me solve this issue?
You should look at the document called "Buttons" that's referenced in the UIButton Class Reference. When you add an image to a button (System type), it's added to the left of the title and as a template image, unless you set the rendering mode of the image to UIImageRenderingModeAlwaysOriginal. So, if you want the image to the left, you can do this:
- (IBAction)setImageForSender:(id)sender {
UIImage *buttonImage = [UIImage imageNamed:#"pic2.jpg"];
buttonImage = [buttonImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[sender setImage:buttonImage forState:UIControlStateNormal];
}
If you want the image under the title (and centered in the button) set the background image instead. This shows up normally, you don't have to deal with the rendering mode.
- (IBAction)setImageForSender:(id)sender {
UIImage *buttonImage = [UIImage imageNamed:#"pic2.jpg"];
[sender setBackgroundImage:buttonImage forState:UIControlStateNormal];
}
Here is the relevant portion of that "Buttons" document:
Images
Using the Image (currentImage) field, you can specify an image to
appear within the content of your button. If the button has a title,
this image appears to the left of it, and centered otherwise. The
image does not stretch or condense, so make sure to select an image
that is the proper size to appear in your button. Note that this image
will be automatically rendered as a template image within the button,
unless you explicitly set its rendering mode to
UIImageRenderingModeAlwaysOriginal. For more information, see Template
Images.
The Background (currentBackgroundImage) field allows you to specify an
image to appear behind button content and fill the entire frame of the
button. The image you specify will stretch to fill the button if it is
too small. It will be cropped if it is too large.
That the last piece of information in the text above about the image being cropped if it's too large, only happens if you set a specific size for your button. If its size is determined by its intrinsic content size (that's the default if you just drag out a button in IB and don't give it size constraints), it will expand to the size of the image.
EDIT: After updating to iOS 7.0.3 the problem is gone
I would like the UIImagePickerController to display photos in a way that the user can access most recent photos first (I am working with iOS7).
I am following this answer https://stackoverflow.com/a/10023924/2007515 , so my function looks like:
- (IBAction)action_album:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
But the result is not what I want:
the "Photos" overview is presented (good)
if I pick "Camera Roll" the oldest photos are displayed on top and I have to scroll all the way down to get the most recent ones (not good)
Could someone tell me what I'm missing here? Thank you.
Just figured this out. This seems to be some kind of Apple bug. If your statusbar is hidden when using the UIImagePickerController, the image picker does not automatically scroll to the bottom (newest) and stays at the top (oldest). If I let the status bar show when using the image picker, it auto scrolls to the bottom like it should. Thanks a lot, Apple.
I have a transparent view with a rectangle drawn onto it using CoreGraphics.
When the camera launches the custom overlay view is above the shutter animation.
What you see is the standard camera shutter with the custom rectangle above it.
How do I get it to go in the right place, underneath the shutter animation? I've looked at other sample code but it's for OS 3.1 and doesn't seem to do anything differently.
Here's my code:
-(IBAction)cameraButton{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerCameraDeviceRear]){
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Add the OverlayView with the custom Rectangle
CGRect overlayFrame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
OverlayView *overlayView = [[OverlayView alloc]initWithFrame:overlayFrame];
picker.cameraOverlayView = overlayView;
[overlayView release];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
On the iPad this problem doesn't exist, and the overlay view is behind the shutter animation by default. But on the iPhone, the overlay appears at front.
I've found a solution that worked for me.
You have to set your overlay view as a subview in this method:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (!viewController)
return;
UIView* controllerViewHolder = viewController.view;
UIView* controllerCameraView = [[controllerViewHolder subviews] objectAtIndex:0];
UIView* controllerPreview = [[controllerCameraView subviews] objectAtIndex:0];
[controllerCameraView insertSubview:self.overlayView aboveSubview:controllerPreview];
}
Hope it helps
Original source:
http://www.alexcurylo.com/blog/2009/06/18/uiimagepickercontroller-in-3-0/
You may not do anything else other than what you're already doing; if iOS decides to put your overlay view over the shutter, you'll just have to live with it (unless you want to risk getting rejected from the app store).
As an imperfect workaround, you could start your overlay with alpha=0 and then set alpha to 1 a second or two later. But there is no set time period that the shutter appears for before 'opening' (I think it depends on how long it takes to initialize the camera hardware), so sometimes your interface might not appear until late and sometimes might appear too early.
As of 4.3.3, the shutter animation is broken because elements are displayed on top, and then snap underneath when the animation starts. I've filed this as a Radar: http://openradar.appspot.com/radar?id=1204401
I answered a similar question here. What worked for me (in iOS 6) was setting the cameraOverlayView in navigationController:willShowViewController:animated.
- (void) navigationController:(UINavigationController*) navigationController willShowViewController:(UIViewController*) viewController animated:(BOOL) animated {
self.imagePickerController.cameraOverlayView = ...; // your camera overlay view
}
I have a custom UIView that I have created to display my custom buttons and toolBar. When I first called for it to show, the bar is on top of the Shutter (which is good). But after the camera is loaded, the shutter comes in front of it, then opens.
If you look at the native camera.app, it doesn't do this. The toolbar stays there the whole time. Here is my code:
// .h
UIImagePickerController *theCamera;
#property (nonatomic, retain) UIImagePickerController *theCamera;
// .m
theCamera = [[UIImagePickerController alloc] init];
theCamera.delegate = self;
theCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
theCamera.showsCameraControls = NO;
theCamera.toolbar.alpha = 0;
theCamera.navigationBarHidden = YES;
theCamera.toolbarHidden = YES;
theCamera.wantsFullScreenLayout = YES;
theCamera.cameraViewTransform = CGAffineTransformMakeScale(1.25, 1.25);
UIImageView *tabBarBack = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tab_bar_back.png"]];
tabBarBack.frame = CGRectMake(0, 422, 320, 58);
[customView addSubview:tabBarBack];
theCamera.cameraOverlayView = customView;
[self presentModalViewController:theCamera animated:YES];
Obviously there are more buttons I add to the customView, but you get the concept.
Subscribe to:
AVCaptureSessionDidStartRunningNotification
This is when the iris open animation begins. If you add a cameraOverlayView during this time, it will be properly covered up by the iris. It is posted at the same time as that PL… private notification. This is a documented approach that does not risk app rejection.
AFAIK there is no direct way to do this. If you use cameraOverlay, you will get shutter for the complete screen.
How ever there are some alternate methods (playing around with the view hierarchy) that will help you in making your preview screen as parent view. I am not sure if this approach is correct as per app store guidelines.
have a look at Hide/Show iPhone Camera Iris/Shutter animation for better understanding on how to achieve this.
On iOS 6+, if you've added your controller as the delegate for the UIImagePickerController, this code should ensure that the shutter stays behind your cameraOverlayView:
- (void) navigationController:(UINavigationController*) navigationController willShowViewController:(UIViewController*) viewController animated:(BOOL) animated {
self.imagePickerController.cameraOverlayView = ...; // your camera overlay view
}
I haven't tested on versions of iOS prior to iOS 6 though.
I have a problem with my PickerController.
I have a launcherView with 4 buttons. Each button opens another View.
When I open my PickerController, all works fine but when I return to my LauncherView and open my PickerController, the "Cancel" and "Take picture" buttons are not clickable.
If I click the "Change camera" button (with my iPod new generation 2 camera), buttons are clickable.
Anyone can help me?
Did you reference the class correctly? This is a sample to see if fixes your issue, make sure the delegate is there and allows Image Editing = YES:
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.allowsImageEditing = YES;
self.imagePickerController.delegate = self;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;