IOS 7 + For force controller Orientation to Portrait - iphone

I have used below code for IO6 and below to force rotate:
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIApplication* application = [UIApplication sharedApplication];
if (application.statusBarOrientation != UIInterfaceOrientationPortrait)
{
UIViewController *c = [[UIViewController alloc]init];
[c.view setBackgroundColor:[UIColor redColor]];
[self.navigationController presentViewController:c animated:NO completion:^{
[self.navigationController dismissViewControllerAnimated:NO completion:^{
}];
}];
}
}
But it is not working correctly on IOS7, it rotate view controller but again set blank view on screen...
Can you help me to solve this issue in IOS 7...

Change this line:
[self.navigationController dismissViewControllerAnimated:NO completion:^{
}];
To this:
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];

Related

presentViewController:imagePickerController is popping my navigationController?

I am using presentViewController:imagePickerController to display the UIImagePickerController. For some reason when I end up dismissing that controller my original navigation controller looses it's stack and my application is back at the root view controller.
I am logging self.navigationController.viewControllers and I can see that after I run the presentViewController:imagePickerController line my navigation controller looses all of its controllers except for the root controller.
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
imagePickerController.navigationBarHidden = YES;
self.imagePickerController = imagePickerController;
DLog(#"self.navigationController:%#",self.navigationController.viewControllers);
[self.navigationController presentViewController:imagePickerController animated:YES completion:^{
DLog(#" after presenting self.navigationController:%#",self.navigationController.viewControllers);
}];
////Closing it
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
DLog(#"self.navigationController:%#",self.navigationController.viewControllers);
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];
}
/////Where my NC is set up
OFMainViewController *mainController = [[OFMainViewController alloc]init];
mainController.managedObjectContext = self.managedObjectContext;
navigationController = [[UINavigationController alloc]initWithRootViewController:mainController];
[self.window setRootViewController:navigationController];
Instead of using self.navigationController use self for both dismissing and calling the imagepickerviewcontroller.
You should present imagePickeController on self instead of self.navigationController.
[self presentViewController:imagePickerController animated:YES completion:^{
DLog(#" after presenting self:%#",self.navigationController.viewControllers);
}];
And dissmiss it accordingly:
////Closing it
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
DLog(#"self.navigationController:%#",self.navigationController.viewControllers);
[self dismissViewControllerAnimated:YES completion:^{
}];
}

Cocos2d, iOS 6.1, GameCenter Crash When Showing Leader-board

I am trying to show a Leader-board in my Cocos2d Game. The code below works correctly on iOS 5.0. However on 6.1 it crashes with the error message below. Thanks in advance for any suggestions.
* Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View > is associated with . Clear this association before associating this view with .'
- (void)showLeaderboard:(id)sender
{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != NULL)
{
leaderboardViewController = [[UIViewController alloc] init];
leaderboardController.category = self.currentLeaderBoard;
leaderboardController.leaderboardDelegate = self;
[leaderboardViewController setView:[[CCDirector sharedDirector] openGLView]];
[leaderboardViewController presentViewController:leaderboardController animated:YES completion:nil];
}
}
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[leaderboardViewController dismissViewControllerAnimated:YES completion:nil];
[viewController release];
}
Try to stop openGL animation and resume back.
-(void)showLeaderboard
{
[[CCDirector sharedDirector] stopAnimation];
GKLeaderboardViewController *leaderboardViewController = [[[GKLeaderboardViewController alloc] init] autorelease];
leaderboardViewController.leaderboardDelegate = self;
AppController *app=(AppController*)[UIApplication sharedApplication].delegate;
[app.navController presentModalViewController:leaderboardViewController animated:YES];
}
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
AppController *app=(AppController*)[UIApplication sharedApplication].delegate;
[app.navController dismissModalViewControllerAnimated:YES];
[[CCDirector sharedDirector] startAnimation];
}

UIImagePickerController when dismissed pushes view to 20 px up in iOS 6.0 only

EDIT : I am using UIStoryBoard.
I have presented like this:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //| UIImagePickerControllerSourceTypeSavedPhotosAlbum ;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
imagePicker.allowsEditing = YES;
[self.navigationController presentViewController:imagePicker animated:YES completion:^{
}];
}
}
Now when dissmissed
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = info[UIImagePickerControllerEditedImage];
NSLog(#"Image : %#",image);
[self dismissViewControllerAnimated:YES completion:^{
}];
}
Now view becomes like this as shown in fiqure :
EDIT : view gets pushed up to 20px when dissmissed.
EDIT : This is only in iOS 6.0 only
The reason was i was setting frame of view controller which is in protrait mode as its previous view was in landscape mode.
self.view.bounds = CGRectMake(0,0,...,...);
Whenever imagepicker dissmiss got called it moved to original position as mentioned.
Now changed in structure for orientation without setting self.view frame externally solved my problem.
If that blue part of view is custom UIView then you should check the auto resizing mask for that view. You will find the problem.
I have similar problem, and in my case 20 pixels was the status bar height.
So, try to set status bar visibility to NO before showing imagePicker and YES when it finished (in delegate methods).
something like this:
[UIApplication sharedApplication].statusBarHidden = YES;
[self.navigationController presentViewController:imagePicker animated:YES completion:^{
}];
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// ... your code here
[UIApplication sharedApplication].statusBarHidden = NO;
[self dismissViewControllerAnimated:YES completion:^{
}];
}
I had similar issue on iOS 8.2. After picking video using UIImagePickerController the frame is increased by 20px, top area of view controller is looking good, but the bottom is cut off.
The solution is:
-(void)openPicker {}
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
//configure image picker here
[self presentViewController:picker animated:YES completion:NULL];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(showStatusBar) userInfo:nil repeats:NO];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
-(void)showStatusBar {
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
});
}

Show another ViewController

help me please. How can I show another view controller after dismissing the existing one? here is my code:
- (void)matchmakerViewControllerWasCancelled:
(GKMatchmakerViewController *)viewController{
[self dismissModalViewControllerAnimated:YES];
ViewController *Vc = [[ViewController alloc]init];
[self presentModalViewController:Vc animated:YES];
}
My code doesn't work. Help me please. If i wrote NSLog after dismissingModalViewController, it shows me that NSLog, but ViewController won't show. thanks
[self dismissModalViewControllerAnimated:YES]; has been deprecated. Try doing:
- (void)matchmakerViewControllerWasCancelled:
(GKMatchmakerViewController *)viewController{
[self dismissViewControllerAnimated:YES completion:^{
ViewController *Vc = [[ViewController alloc]init];
[self presentViewController:Vc animated:YES completion:^{}];
}];
}
Simply check this
[self dismissModalViewControllerAnimated:NO];
Nextview *sec = [[Nextview alloc] initWithNibName:#"Nextview" bundle:nil];
[self presentModalViewController:sec animated:YES];
[sec release];
Hope this works.

How to fix the UIModalTransitionstyle issue on ios6?

I am using the following code for UIModalTransitionStyle view in my application when i click the button
InfoViewController *infoViewController = [[InfoViewController alloc]initWithNibName:#"InfoViewController" bundle:nil];
infoViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.presentedViewController presentViewController:infoViewController animated:YES completion:NULL];
its worked perfecly in ios5 but i update the application ios6 it not worked. How can I handle this issue
This code works, tested in iOS 6.0 simulator.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:#"http://videoURL"]];
self.moviePlayerController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:self.moviePlayerController animated:YES completion:nil];
}
Since the URL is invalid, the MPMoviePlayerViewController will just endlessly flip back and forth, but the point is that it works.