UIViewController parent not rotating after modal view is dismissed - ipad

I have a UIViewController on an iPad that I am displaying modally.
However after dismissing it, the view controller that displayed it does not change in orientation and acts as if the underlying view controller did not change, unless the device is rotated back and forth.
I'm using these methods in the modal view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
[self updateUI];
return YES;
}
- (BOOL)shouldAutorotate {
[self updateUI];
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
-(void) updateUI{
}
The underlying UINavigationController code (the one that doesn't change itself properly once the modal view controller is dismissed):
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
[self adjustUIForOrientation:interfaceOrientation];
return YES;
}
- (BOOL)shouldAutorotate {
[self adjustUIForOrientation:[self preferredInterfaceOrientationForPresentation]];
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
- (void) adjustUIForOrientation: (UIInterfaceOrientation)interfaceOrientation {
if(UIDeviceOrientationIsPortrait(interfaceOrientation)) {
[_landscapeTemplate hide];
[_portraitTemplate show];
_activeTemplate = _portraitTemplate;
} else {
[_portraitTemplate hide];
[_landscapeTemplate show];
_activeTemplate = _landscapeTemplate;
}
}
-(IBAction) signInButtonTouched: (id) sender{
if (![Session shared].loggedInUser){
UserProfileLoginViewController *userProfileLoginVC = [[[UserProfileLoginViewController alloc] initWithNibName:#"UserProfileLoginViewController" bundle:nil] autorelease];
userProfileLoginVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
//self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:userProfileLoginVC animated:YES completion:nil];
// [self pushViewController:userProfileLoginVC animated:YES];
[userProfileLoginVC.emailTextField becomeFirstResponder];
}
else [[Session shared] explicitEnd];
}
Is there a way to make this work? Basically it appears that the view controller that presented the modal view controller is not getting the rotation calls forwarded to itself.

Related

hiding a view in viewDidAppear

I am having a small problem.I have a view which should be set to hidden when the view loads is tried to add
[self.view setHidden:YES];
in viewWillAppear and the view is hiding but the Hiding of view is visible(it takes a split second to hide after the app is loaded).I need to hide the view without it visible.Help me ?
My full code in viewDidAppear
-(void)viewDidAppear:(BOOL)animated
{
#try {
NSLog(#"\n\n--------------Mainview Controller------------\n");
// Guided access mode call mainview in iOS7. It making issue in UI
[getStartBox setHidden:NO];
appDel.deviceModel=[self platformString];
if([MainView checkRegistrationStatus])
{
NSLog(#"Already registered....");
[main setGlobalValues];
if ([appDel.configArray count]==0)
{
NSLog(#"Load app sync page...");
[self.view setHidden :YES];
// [_mainView setHidden:YES];
AppSync *sync=[[AppSync alloc]initWithNibName:#"AppSync" bundle:nil];
sync.appSyncData = configureData;
[self presentViewController:sync animated:NO completion:nil];
}
else
{
NSLog(#"%#",appDel.logInStatus);
if([appDel.logInStatus isEqualToString:#"false"])
{
[self.view setHidden :YES];
// [_mainView setHidden:YES];
NSLog(#"Load login view controller...");
appDel.isEmergencyAlertOn=NO;
appDel.isRespondingToAlert=NO;
LogInViewController *loginView=[[LogInViewController alloc]initWithNibName:#"LogInViewController" bundle:nil];
[self presentViewController:loginView animated:NO completion:nil];
}
else if([appDel.logInStatus isEqualToString:#"true"])
{
NSLog(#"Load alert screen");
[self.view setHidden :YES];
// [_mainView setHidden:YES];
AlertScreen *alert=[[AlertScreen alloc]initWithNibName:#"AlertScreen" bundle:nil];
alert.alertData=notificationData;
[self presentViewController:alert animated:NO completion:nil];
}
}
}
else
{
appDel.domainName=nil;
// Version number reffered in settings page. The log enabled one should be in same format (Ex Version 1.0.53(log enabled))
versionLabel.text=#"Version 1.3(log enabled)";//(log enabled)
appDel.appVersion=versionLabel.text;
//self.view.layer.contents=(id)[[UIImage imageNamed:#"background.png"]CGImage];
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]]];
ConfigureButton.hidden=NO;
}
}
#catch (NSException *exception) {
[[WriteLogger getWriteLogger] writeLog:moduleName sourceClass:self.nibName methodName:#"viewDidAppear" errorMsg:exception];
}

Achievements screen's "Done" button not working on some devices

I'm using GKAchievementViewController to display achievements. It works fine on most devices, but on some (iPod Touch 3rd Gen and iPad 1 running iOS 5.1.1) taping the Done button does nothing.
I have no idea how to debug this...
Here is the code I'm using to display the achievements:
viewController = [[GKAchievementViewController alloc] init];
if (viewController)
{
viewController.achievementDelegate = self;
[self presentModalViewController:viewController animated:YES];
}
and then:
- (void)achievementViewControllerDidFinish:(GKAchievementViewController *)aViewController
{
[self dismissModalViewControllerAnimated:YES];
}
Should work when implementing achievementViewControllerDidFinish:
- (void) achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
[viewController.delegate dismissModalViewControllerAnimated:YES];
}
Answering my own question in case anyone has the same problem.
This seems to have solved the issue:
- (void)achievementViewControllerDidFinish:(GKAchievementViewController *)aViewController
{
if ([self respondsToSelector:#selector(dismissViewControllerAnimated:completion:)])
{
[self dismissViewControllerAnimated:YES completion:^{
aViewController.achievementDelegate = nil;
[aViewController release];
}];
}
else
{
[self dismissModalViewControllerAnimated:YES];
aViewController.achievementDelegate = nil;
[aViewController release];
}
}

Views Not Resizing After Rotation In Custom Container Controller

I've made a test app to familiarize myself with making a custom container view controller. If I rotate the device when the app first starts or after switching to a different view controller, the new view resizes to take up the whole screen, as I intended. However, if I rotate after the app starts, and then switch to a new view controller, the view keeps its portrait size instead of getting shorter and wider (actually it's slightly different -- it goes from 320,460 to 300,480). The master view controller is alloc init'd in the app delegate (no xib) and set as the window's root view controller. Here is the code I have in my MasterViewController (the custom container controller):
- (void)viewDidLoad {
[super viewDidLoad];
WelcomeController *welcome = [[WelcomeController alloc] initWithNibName:#"ViewController" bundle:nil];
self.currentController = welcome;
[self addChildViewController:welcome];
[self.view addSubview:welcome.view];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeLeft:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
}
- (void)swipeLeft:(UISwipeGestureRecognizer *)gesture {
if (gesture.state == UIGestureRecognizerStateRecognized) {
UIActionSheet *sheet =[[UIActionSheet alloc] initWithTitle:#"Select A Destination" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"welcome",#"Play",#"Scores", nil];
[sheet showInView:self.view];
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:{
if ([self.currentController class] != [WelcomeController class] ) {
WelcomeController *welcome = [[WelcomeController alloc] initWithNibName:#"ViewController" bundle:nil];
[self addChildViewController:welcome];
[self moveToNewController:welcome];
}
break;
}
case 1:{
if ([self.currentController class] != [PlayViewController class] ) {
PlayViewController *player = [[PlayViewController alloc] initWithNibName:#"PlayViewController" bundle:nil];
[self addChildViewController:player];
[self moveToNewController:player];
}
break;
}
case 2:{
if ([self.currentController class] != [HighScores class] ) {
HighScores *scorer = [[HighScores alloc] initWithNibName:#"HighScores" bundle:nil];
[self addChildViewController:scorer];
[self moveToNewController:scorer];
}
break;
}
case 3:
NSLog(#"Cancelled");
break;
default:
break;
}
}
-(void)moveToNewController:(id) newController {
[self.currentController willMoveToParentViewController:nil];
[self transitionFromViewController:self.currentController toViewController:newController duration:.6 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{}
completion:^(BOOL finished) {
[self.currentController removeFromParentViewController];
[newController didMoveToParentViewController:self];
self.currentController = newController;
}];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;//(interfaceOrientation == (UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft));
}
Any ideas why this is happening (I don't know if this means that the master view controller's view isn't resizing, but when I get this non-resizing behavior the gesture recognizer only responds in the narrow view, not over the whole screen)?
You are not sending rotation messages to your child view controllers. At least not in the code you posted. After switching Child Controller you are even removing previous child from ChildViewControllers array with [self.currentController removeFromParentViewController] so even if you implement - (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers you have always only one ChildViewController in your ParentViewController.
I have got this working, so i will paste you how am i doing this. First i create all my ViewControllers, add them as child view controllers to ParentViewController. Then call didMoveToParentViewController: method.
//Controller1
Controller1 *c1 = [[Controller1 alloc] init];
c1.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self addChildViewController:c1];
[c1 didMoveToParentViewController:self];
//Controller2
Controller2 *c2 = [storyboard instantiateViewControllerWithIdentifier:#"c2"];
index.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self addChildViewController:c2];
[c2 didMoveToParentViewController:self];
c2.view.frame = m_contentView.frame;
[self.view addSubview:c2.view]; //It is in initial screen so set it right away
m_selectedViewController = c2;
//Controller3
Controller3 *c3 = [storyboard instantiateViewControllerWithIdentifier:#"c3"];
compare.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self addChildViewController:c3];
[c3 didMoveToParentViewController:self];
m_controllers = [NSArray arrayWithObjects:c1, c2, c3, nil]; //Hmm now i think this is not needed, I can access viewController directly from self.childViewControllers array
Then I implemented
- (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers
{
return YES;
}
Switching to child view controller is done with this code
if (value < m_controllers.count)
{
UIViewController *contentViewController = [m_controllers objectAtIndex:value];
contentViewController.view.frame = m_contentView.frame;
[self transitionFromViewController:m_selectedViewController toViewController:contentViewController duration:0 options:UIViewAnimationOptionTransitionNone animations:nil completion:^(BOOL finished) {
m_selectedViewController = contentViewController;
}
];
}
This should be enough. But i have got some issues with this so i send rotation messages to unactive Childs myself.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
for (UIViewController *vc in m_controllers)
{
if(vc != m_selectedViewController)
[vc willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
for (UIViewController *vc in m_controllers)
{
if(vc != m_selectedViewController)
[vc willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
for (UIViewController *vc in m_controllers)
{
if(vc != m_selectedViewController)
[vc didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
}
manually added
self.view.autoresizesSubviews = YES;
inside
- (void)viewDidLoad
and it solved the problem,
for some reason the value inside storyboard was not being used i guess

UIDocumentInteractionController on the detailView

I'm previewing a file using UIDocumentInteractionController, but it is occupying all the area of the iPad. I would like it to appear on the detail view of the split view controller. I've checked that the UIView of my view controller doesn't occupy all the screen. Any ideas? I checked that the documentInteractionControllerRectForPreview: is called.
-(void)requestExecutedWithSuccess:(Model *)model {
UIDocumentInteractionController *docInteractionCont = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:model.filePath]];
self.docInteractionController = docInteractionCont;
self.docInteractionController.delegate = self;
BOOL attachmentShown = [self.docInteractionController presentPreviewAnimated:YES];
...
}
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
return [self navigationController];
}
- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
{
return self.view;
}
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller
{
return self.view.frame;
}

dismissModalViewControllerAnimated function not dismissing the view

I am trying to use dismissModalViewController:Animated: to dismiss my view, but it is not dismissing it, no matter what I try. You can see my attempts to release the view in the hideSplash method at the bottom. Please, if anyone can help it would be greatly appreciated. My code posted below:
#import "SplashViewController.h"
#implementation SplashViewController
- (void) didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void) viewDidUnload {
}
- (void) dealloc {
[super dealloc];
}
-(void) showSplash {
modalViewController = [[UIViewController alloc] init];
modalViewController.view = modelView;
[self presentModalViewController:modalViewController animated:NO];
[activityIndicator startAnimating ];
//[self bigcalculation];
//[self performSelector:#selector(hideSplash) withObject:nil afterDelay:2.0];
}
- (void) viewDidAppear:(BOOL)animated {
NSLog(#"View Did Appear");
[self bigcalculation];
}
- (void) bigcalculation {
NSLog(#"Big Calc Start");
for (int i = 0; i <= 648230; i++) {
for (int j = 0; j <= 1200; j++) {
}
}
NSLog(#"Big Calc End");
[self performSelector:#selector(hideSplash) withObject:nil];
}
- (void) hideSplash {
NSLog(#"Hide");
//[self dismissModalViewControllerAnimated:NO];
//[[self parentViewController] dismissModalViewControllerAnimated:YES];
[[self modalViewController] dismissModalViewControllerAnimated:YES];
NSLog(#"End Hide");
}
#end
The modal view controller is not responsible for dismissal. That burden is placed on the view controller that called the modalViewController.
Try replacing:
[[self modalviewController] dismissModalViewControllerAnimated:YES];
with
[self dismissModalViewControllerAnimated:YES];
Try to use this:
[self.parentViewController dismissModalViewControllerAnimated:NO];
I found the solution in case anyone else has this issue the line
[self performSelector:#selector(hideSplash) withObject:nil];
Should be
[self performSelector:#selector(hideSplash) withObject:nil afterDelay:0.0];

Resources