UIImage Picker autorotation feature disappeared suddenly - rotation

I was using UIImagePickerController without any problem.
Before when I was taking a picture in the landscape mode, the picture in the Preview (when the buttons Retake and Use Photo were present) was always automatically rotated so as to appear correctly in the portrait mode.
But now when I use the UIImagePickerController the preview mode does not rotate the picture anymore.
Where can I activate or desactivate this mode?
Here is my code:
- (IBAction)getCameraPicture{
//Create an UIImagePickerController to be able to take a picture
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsImageEditing = NO;
[self presentModalViewController:picker animated:YES];
[picker release];
- (IBAction)selectExistingPicture{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;//Here is specified the fact that the picker source is the library
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error accessing photo library" message:#"Device does not support a photo library" delegate:nil cancelButtonTitle:#"Drat!" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
int imageCase=0;
UIImage *imageSaved=rotateImage(image);
UIImage* imageNormal =scaleImage(imageSaved,imageCase);
imageView.image = imageNormal;
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}
I really need to at least understand what is happening so any help would be really appreciated even if it is not the solution!
Thanks folks!

one possibility is that you need to call
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

Related

Presented UIImagePickerController camera could take photo or cancel

I have UIImagePickerController which opens a camera, as the sample code bellow shows.
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
imagePicker.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentViewController:imagePicker
animated:YES
completion:NULL];
My Problem: When I present the camera, the camera shows, but I could not take a picture nor tap to cancel. Even the flip camera icon does not respond.
Happening on iOS versions below 8, iPad.
i tried your code and its working on iPad 2 iOs7.1.2
you might try using setters, this is how i am doing it
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[picker setAllowsEditing:YES];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[picker setModalPresentationStyle:UIModalPresentationPageSheet];
}
else
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[picker setDelegate:self];
[self presentViewController:picker animated:YES completion:nil];

ALAssetsLibrary writeImageToSavedPhotosAlbum block the program in iOS8

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSMutableDictionary* meta = [[NSMutableDictionary alloc] initWithDictionary:[info objectForKey:UIImagePickerControllerMediaMetadata]];
UIImage* img = [info objectForKey:UIImagePickerControllerOriginalImage];
if(self.locationManager.location){
NSDictionary* locationMeta = [self gpsDictionaryForLocation:self.locationManager.location];
[meta setObject:locationMeta forKey:(NSString*)kCGImagePropertyGPSDictionary];
}
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:img.CGImage metadata:meta completionBlock:^(NSURL* assetUrl, NSError* error){
//.......
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
This code worked fine in iOS7. After I upgraded my device to iOS8, the program was blocked and imagePickerView didn't dismiss.
Is this a bug in iOS8? Anyone can help me?

Take Photos from camera and library

hi in my app i am able to take a photo or select a photo from library and display it in a imageview
but my question is how can i add a second image view and display a image in that
here is my code
- (IBAction)TakePhoto:(id)sender {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)ChoosePhoto:(id)sender {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[ImageView setImage:image]; // "myImageView" name of any UImageView.
[self dismissViewControllerAnimated:YES completion:NULL];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:NULL];
}
What I think from your question is you are going to select two image one bye one.
Either from camera or from photo library.
Try this one:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
if(ImageView.image == Nil)
{
[ImageView setImage:image];
}
else if(ImageView2.image == Nil)
{
[ImageView2 setImage:image];
}
[self dismissViewControllerAnimated:YES completion:NULL];
}

iOS6 problems to Tweet in UITabBarController using image taken from UIImagePickerController

After picking image from UIImagePickerController I want to Tweet it but there is error!
Warning: Attempt to present <SLTwitterComposeViewController: 0x210d84b0> on <UITabBarController: 0x1fd67650> while a presentation is in progress!
P.S
This is tabbar application (4 tabbars)
All code:
-(void)useCamera:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController *imagePicker =[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
_newMedia = YES;
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
[self buttonTweet:info[UIImagePickerControllerOriginalImage]];
}
}
- (IBAction)buttonTweet:(id)sender {
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composeController setInitialText:[NSString stringWithFormat:#"#this is tweet text"]];
[composeController addImage:sender];
[composeController addURL: [NSURL URLWithString:#"http://www.abc.com"]];
[self presentViewController:composeController animated:YES completion:nil];
}
You are presenting a new view controller while the old one is still disappearing. You can present the new one upon completion of the other animation by doing it like this:
[self dismissViewControllerAnimated:YES completion:^{
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
[self buttonTweet:info[UIImagePickerControllerOriginalImage]];
}
}];

Game Center? Xcode

I have been working ver hard on Game center. I have tested so many codes I've lost count.
I would love to know how to automatically submit score as well
here are some codes i have used but i am not sure if this will help
-(IBAction)showleaderboard:(id)sender{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc]init];
if (leaderboardController !=NULL) {
leaderboardController.category = self.currentLeaderboard;
leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
leaderboardController.leaderboardDelegate = self;
[self presentModalViewController:leaderboardController animated:YES];
}
}
-(void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController{
[self dismissModalViewControllerAnimated:YES];
[viewController release];
}
-(IBAction)showAchivementLeaderboard:(id)sender{
GKAchievementViewController *achivements = [[GKAchievementViewController alloc]init];
if (achivements !=NULL) {
achivements.achievementDelegate = self;
[self presentModalViewController:achivements animated:YES];
}
}
-(void)achievementViewControllerDidFinish:(GKAchievementViewController *)viewController{
[self dismissModalViewControllerAnimated:YES];
[viewController release];
}
self.currentLeaderboard= kEasyLeaderboardID;
if ([gameCenterManager isGameCenterAvailible]) {
self.gameCenterManager= [[[GameCenterManager alloc] init] autorelease];
[self.gameCenterManager setDelegate:self];
[self.gameCenterManager authenticateLocalUser];
}else{
UIAlertView *openURLAlert = [[ UIAlertView alloc] initWithTitle:#"Game Center turned off" message:#"You are not connected to game center." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[openURLAlert show];
[openURLAlert release];
}
To report a score you need to use GKScore as follows;
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:self.gameCategory.leaderboardString];
scoreReporter.value = score;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil) {
[[KYTGlobals instance] storeScore:score forCategory:self.gameCategory.leaderboardString];
}
}];
The above code allocates and inits a GKScore object using the identifier that you have already set up on game center for the category that you want to report a score for. You update the value for the score and then use reportScoreWithCompletionHandler making sure to test for error so that you can archive the score and report it later.

Resources