I load a view controller in my code using a segue in UIStoryboard. Based on a few user selected options, I then hide or show a UI control using an animation. It all works fine.
- (void)showComments {
NSLog(#"Show Comments");
_commentsTextView.hidden = NO;
_commentsTextView.frame = CGRectMake(435, 266, 475, 134);
[UIView animateWithDuration:1 animations:^{
_commentsTextView.alpha = 1;
_signatureButton.frame = CGRectMake(435, 420, 475, 134);
_cancelButton.frame = CGRectMake(568, 581, 100, 44);
_finishedButton.frame = CGRectMake(676, 581, 100, 44);
}];
}
Then I am presenting a view controller created in UIStoryboard using the following code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
SigningViewController *signingVC = (SigningViewController *)[storyboard instantiateViewControllerWithIdentifier:#"SigningViewController"];
signingVC.object = self;
signingVC.signatureProperty = #"employeeSignature";
signingVC.startDate = self.startDate;
signingVC.endDate = self.endDate;
[self presentViewController:signingVC animated:YES completion:nil];
When this code fires all happens as expected except for one thing: All the custom animations that hid or showed a UI control revert back. It is as if by calling the presentViewController method, it is redrawing my existing view from the UIStoryboard.
Is there a way to get it to quit redrawing/reload my existing view from the Storyboard before displaying the new view modally?
I had the same problem too. Whatever I tried to make an animation change whenever a modal closed it seemed to reset back to the original storyboard.
The solution I had to go with was to add any animation view as an outlet to the header file. Take off the view out of the self.view or main view of the view controller on the storyboard and programmatically add it as a subview. Set the frame to where you want it and all the animation positions should be the same after you end the modal. It worked for me if you need more explanation and let me know.
I had just the same problem and posted it here in a more detailed form, A user named kokx helped me a lot and the answer is documented in my question page.
Related
I just have one question related to presenting a from sheet view controller in iOS 8. In iOS 7 I was able to change the height of the view controller using the last line of code in the function below:
SendRemainingEvaluationsViewController *sendRemainingEvaluationViewController = [[[SendRemainingEvaluationsViewController alloc] initWithNibName:#"SendRemainingEvaluationsViewController" bundle:nil]autorelease];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:sendRemainingEvaluationViewController] autorelease];
navigationController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navigationController animated:YES completion:nil];
//To Change the default size of the viewController which is presented in UIModalPresentationFormSheet presentation style
navigationController.view.superview.frame = CGRectMake(navigationController.view.superview.frame.origin.x, navigationController.view.superview.frame.origin.y, navigationController.view.superview.frame.size.width, 230);
But this does not work on iOS 8, not sure why? Does anyone knows what is the problem? any idea will be appreciated.
Thanks in advance.
After checking it, I could figure out the problem. After initializing the view navigation controller, its superview is nil and you can't access it right after presenting it. As a workaround, you can change the frame of its superview in the viewwillAppear of the view controller you're trying to present as you can see below:
- (void) viewWillAppear:(BOOL)animated
{
self.parentViewController.view.superview.frame = CGRectMake(self.parentViewController.view.superview.frame.origin.x, self.parentViewController.view.superview.frame.origin.y, self.parentViewController.view.superview.frame.size.width, 230);
}
This should work.
I know this is a very popular issue, but i´m having a hard time...so if anyone could help, it would most appreciate:
Im my master tableview (that i have made in storyboard) i have a plus button and every time the user presses that button, a picker view appears...depending on the selection in the picker view, a modal view appears (for this modal view, i have dragged a simple view controller in storyboard and gave it a storyboard id). Each modal view has textfields, and i want to dismiss the keyboard every time the user enters something...to create the modal view i have done this:
CobTableview *produtoCob =[self.storyboard instantiateViewControllerWithIdentifier:#"cobId"];
produtoCob.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:produtoCob animated:YES completion:nil];
produtoCob.view.superview.frame = CGRectMake(0, 0, 350, 512); //do this after presentModalViewController
produtoCob.view.superview.center = self.view.center;
produtoCob.managedObjectContext = self.contextProd;
How can i resolve this?
To everyone that has the same issue...i found out that you need both methods in your modal view controller class :
- (BOOL)disablesAutomaticKeyboardDismissal
return NO
-(BOOL)textFieldShouldReturn:(UITextField *)textField
([textField resignFirstResponder];
return yes
i am making a customized back button which works exactly as a real back button does. below is my code
UIButton *cusBack = [UIButton buttonWithType:101];
[cusBack setTitle:#"Back" forState:UIControlStateNormal];
[cusBack addTarget:self action:#selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
self.view addSubView:cusBack;
and here is my selector:
-(void)clickBack{
PrevPage *pPage = [[PrevPage alloc] init];
[self.navigationController pushViewController:pPage animated:YES];
[pPage release];
}
actually, it works but the direction it creates is from RIGHT to LEFT. but I want the page to move from LEFT to RIGHT since it goes back to the recent page
thank you!
If you want to have the same behavior as the back button you should try another approach:
-(void)clickBack{ //Your presenting view controller will always be the last view controller on the stack.
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-1] animated:YES];
}
Also, if you need to do some changes to the previous view controller, all you need to do is import it's header file and then you can use it's properties and public methods before popping the view controller.
#import "MyPreviousViewController.h"
...
-(void)clickBack{
[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-1].title = #"Change title for previous view controller";
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-1] animated:YES];
}
Currently, your back button doesn't work as the real back button does, because, instead of popping the last view controller off the stack(also releasing the objects), you actually keep pushing new view controllers on the stack. You might have some issues if this stack gets too big.
I have a PopoverController view that allows a user to download a file. On button press, the popOver view will expand in size, display download status, and the main view controller will be obscured by an unhidden "cover" view that has been added to the PopoverController's "passThroughViews" property so that the user can not accidentally dismiss the pop over while the file is downloading.
My problem is that, in storyboards, my main viewController is embedded in a Navigation Controller. I can't seem to cover the navigation controller's bar with a view in the storyboard, and if the user presses anywhere on the navigation bar then the popover will disappear and the user will lose the download's progress bar.
How do I either cover up the navigation bar with my "cover" view, or how do I add the navigation bar's view to my popOverController's passThroughViews?
Opening the Popover from the main viewController:
- (IBAction)openDataOptionsPopOver:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
PopOverViewController *optionsWindow = [storyboard instantiateViewControllerWithIdentifier:#"dataOptions"];
self.popUp = [[UIPopoverController alloc] initWithContentViewController:optionsWindow];
[self.popUp setDelegate:self];
[nextNavButton setEnabled:NO]; //Disabling barButtonItem on the navigationController
optionsWindow.containerPopOver = self.popUp; //Pointer to the popover, to resize it later.
optionsWindow.coverView = self.coverView; //Pointer to the coverView, to (un)hide later
[popUp presentPopoverFromRect:[sender frame] inView:[sender superview] permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
Setting the passThroughViews property inside of the PopoverViewController:
//Expands the popOver on press of "refreshFileButton" to display progressView
-(void) explodeWindow
{
//setting self.navigationController.view and ...visibleViewController.view here didn't seem to work ...
[containerPopOver setPassthroughViews:[NSArray arrayWithObjects:coverView, nil]];
[containerPopOver setPopoverContentSize:CGSizeMake(600, 400) animated:YES];
[titleBarItem setTitle:#"Downloading File. Please Wait ..."];
[refreshFileButton setHidden:YES];
[progressView setHidden:NO];
[downloadLabel setHidden:NO];
[coverView setHidden:NO];
[progressView setProgress:0.0 animated:NO];
}
I've tried adding self.navigationController.view to passThroughViews with no success--it actually turns out to be a null pointer. And I can't seem to place a UIView at any level in storyboards that will cover all my controls without obscuring the popOver. What am I missing here? And thanks for reading.
Edit:
As Aglaia points out below out, implementing the following, and avoiding passThroughViews, is probably the best way to do this.
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
//Don't dismiss our popover when the view covering our controls is present
if([coverView isHidden]){
return YES;
}else{
return NO;
}
}
Maybe there is something I am missing, but why don′t you just implement a new view controller with its navigation bar set to none and present it modally on button press? Then when the download is finished you just dismiss the view controller.
If you want the user to see the underlying view you can use a UIAlertView instead.
Alternatively set you view controller as the delegate of the popover controller and forbid the user to dismiss your popover on touch outside through
- (BOOL) popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return NO;
}
Then when you want to dismiss it call dismissPopoverAnimated:
to cover the whole screen including navigation bar:
[myView setFrame:[[UIScreen mainScreen] bounds];
[self.navigationController.view addSubview:myView];
Hope you can help. I basically need to add an object to a UIView that is within a UIView.
In interface builder I have my View, and inside that I have another View with an image (map) inside (all done with Interface Builder). The second view I am using a class called "MainGameMapViewController" (reason being is that the first view is static/contains text/scores etc. and the view inside that is the game, and this whole view is draggable with the code in "MainGameMapViewController").
I need to add objects to "MainGameMapViewController" UIView.
I have added a class called "CharMain" and used this code inside the MainViewController:
-(void) viewWillAppear:(BOOL)animated {
CharMain* charMain = [[CharMain alloc] initWithFrame:CGRectMake(40, 280, 0, 0)];
[self.view addSubview:charMain];
}
CharMain contains the code that draws a rect and adds an image, this works fine, BUT it needs to be added to the second view "MainGameMapViewController".
I have tried adding the code inside the MainGameMapViewController file, and it says "error: request for member 'view' in something not a structure or union", I have tried
[self addSubview:charMain];
This comes up with no errors, but the image doesnt appear, how do I make this appear within the second UIView? Thanks!
CharMain* charMain = [[CharMain alloc] initWithFrame:CGRectMake(40, 280, 0, 0)];
//this should be your subview instead of self.view try adding it to your subview's instance.
[MainGameMapViewControllerInstance.view addSubview:charMain];