Empty table rows becomes transparent right before page curl transition - ios

I have a table view. When you add a new item to the table, I display a form sheet for you to enter the name and description of the item to be added to the table. When you press Done, the modal view dismisses and the item's detail view is pushed. Instead of pushing the detail view like you normally would with a navigation controller, I use a page curl transition.
DetailViewcontroller *detailViewcontroller = [[DetailViewcontroller alloc] initWithStyle:UITableViewStyleGrouped];
detailViewcontroller.coolObject = collectionOne;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1.00];
[UIView setAnimationDelay:.25];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:YES];
//Start Animation
[UIView commitAnimations];
[self.navigationController pushViewController:detailViewcontroller animated:NO];
[detailViewcontroller release];
This works perfectly when there's enough populated rows to fill the screen. However, if there's only a few rows populated, the rest of the table becomes transparent where there's no rows right before the page curl transition and you can see parts of the detail view underneath right before the page curl transition loads.
It looks like the detail view is displayed first, then an empty shell of a view curls away after the fact.
I have set the table rows and table background color to black, white, anything but clearColor, and it still does it.
Is it a timing issue? Should I put timing in to make sure that the detail view isn't pushed until after the modal view is dismissed? Maybe tell the Add item controller to display the detail view and not the tableview's addViewDisDimiss delegate method?

Related

Adding Subviews on the top of MainViewController

I am working to get user survey before user starts using my app, it is a typically collection of data for my research.
My problem is to add subview on the top of mainviewcontroller.
I have two subviewcontroller as you can see in the first screenshoots. I would like to add first subview on the mainviewcontroller, and whenever user clicks on next customized button, then firstsubview disappear and secondsubview appear on the top of mainviewcontroller.
firstsubview implemented as follows:
CGRect rect = [firstSurveyViewController.view frame];
rect.origin.x = 5;
rect.origin.y = 5;
[firstSurveyViewController.view setFrame:rect];
[self.view addSubview:firstSurveyViewController.view];
But I want to drop the firstsubview and add the second when user clicks on next button.
How could I implement?
For composing modal view controllers, you have two real options (ignoring cool stuff under NDA):
Use the Container View Controller pattern to insert the inner view controller into its parent.
Add a new window with that view controller, similar to how you would do it in your AppDelegate. Create the window, add your child as a root view controller, make it key and visible. This is actually what UIAlertView does to perform a similar behavior to your app.
I can't say what would be better for your case, but I have more experience with container view controllers so I'll give you the highlights. To add a child view you will need these steps (from the link above) in your parent view controller:
- (void) displayContentController: (UIViewController*) content;
{
[self addChildViewController:content]; // 1
content.view.frame = [self frameForContentController]; // 2
[self.view addSubview:self.currentClientView]; // 3
[content didMoveToParentViewController:self]; // 4
}
This will:
Add your child view controller.
Set the frame to whatever you want. This could be self.view.bounds if you want it to take up the full space.
Add the view to its parent.
Notify the child view controller that it was added.
To remove a child view controller you would do the opposite, again from the link:
- (void) hideContentController: (UIViewController*) content
{
[content willMoveToParentViewController:nil]; // 1
[content.view removeFromSuperview]; // 2
[content removeFromParentViewController]; // 3
}
This will:
Notify your child view controller that it will disappear.
Remove its view from the visual stack.
Remove it from its parent.
You have got two options.
Use both controllers as modal controllers. After tapping Next on first controller, dismiss it and call second controller modally.
Another much better option (in my opinion) is to present these two series of controllers one after another using modal UINavigationController. You can push your controllers in navigation controller, and when done, you can dismiss it and show your main controller.
EDIT
See this post.
Transitioning between views is easy-
1) Straight forward
-(IBAction):onNextButtonClick:(id)sender
{
[self.firstViewController.view removeFromSuperView];
self.secondViewController.view.frame = newFrame;
[self.view addSubView:self.secondViewController.view];
}
2) If you want some fancy animations try this-
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionTransitionCurlDown animations:^{
[self.firstViewController.view removeFromSuperView];
self.secondViewController.view.frame = newFrame;
[self.view addSubView:self.secondViewController.view];
} completion:^(BOOL finished) {
//Completion
}];

Methods gets called when app goes to the background

my app consists of a table view controller and a view controller. when i press a cell in the table view, the toolbar at that view slips with animation down outside the screen and when i'm in the view controller and press back, the toolbar bar slips upwards to it's original position. My problem is, i figured out a bug that when i'm in the view controller and press the home button to exit the app and then come back. the app resumes where i left but when i go back to the table view, the toolbar shifts upwards beyond it's original position. the sliding of the toolbar works fine when i'm in the app before exiting. so there's like something is being called to reset the toolbar to it's origin and thus adding the additional y-axis point to shift more upwards. does anybody know what are those methods?
Code:
i have this in the viewWillAppear method of the view controller:
[UIView animateWithDuration:0.7 animations:^{
self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, self.navigationController.toolbar.center.y + self.navigationController.toolbar.frame.size.height);
} completion:^(BOOL finished){
self.navigationController.toolbar.hidden = YES;
}];
and in the same view when it needs to disappear i added this in the viewWillDisappear:
[[self.navigationController toolbar] setHidden:NO];
[UIView animateWithDuration:1 animations:^{
self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, self.navigationController.toolbar.center.y - self.navigationController.toolbar.frame.size.height);
} completion:^(BOOL finished){
}];
i tried this as another way to animate the hiding of the toolbar but there is no animation:
- (void) viewWillAppear:(BOOL)animated
{
[self.picker setHidden:YES];
[self.navigationController setToolbarHidden:YES animated:YES];
}
- (void) viewWillDisappear:(BOOL)animated
{
[self.navigationController setToolbarHidden:NO animated:YES];
[self.course setValue:self.nameTextField.text forKey:#"courseName"];
[self.course setValue:[NSNumber numberWithInt:[self.creditsTextfield.text integerValue]] forKey:#"courseCredits"];
[self.course setValue:[NSNumber numberWithInt:[self.chaptersTextfield.text integerValue]] forKey:#"courseChapters"];
[self.course setValue:self.gradeTextfield.text forKey:#"courseGrade"];
}
For one thing, you should use frame instead of center, but replace the viewWillDisappear animation line with this:
self.navigationController.toolbar.frame = CGRectMake(0,0,self.navigationController.toolbar.frame.size.width, self.navigationController.toolbar.frame.size.height);
and tell me what happens...
That should fix your problem.
Since you are using the toolbar belonging to a UINavigationController (and not a standalone UIToolbar instantiated and added to a UIView by your own controller), it's better to use the methods that UINavigationController exposes, because you don't know how it manages and move its UIToolbar.
Try to put just this in viewWillAppear:, instead of the entire animation block
[self.navigationController setToolbarHidden:NO animated:YES];
and this in viewWillDisappear:
[self.navigationController setToolbarHidden:YES animated:YES];
i fixed it! i aded the following lines of code in viewWillDisappear:
self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, 458);
self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, self.navigationController.toolbar.center.y + self.navigationController.toolbar.frame.size.height);
since the problem seems that when the app goes background then foreground the toolbar resets to it's original position and thus after navigating back to the table view the toolbar is shifted beyond it's original position. therefore the first line i added resets the toolbar to it's original position while still hidden then shift it down. after that the block of animation is done. i did this so that the animation works on the following cases:
1. the user enters the detail view from the table view then goes back to the tableview without exiting the app.
2. the user enters the detail view from the tableview then exits the app and then resume the app and goes back to the table view.

How to create a UINavigationController that hovers onscreen (not translate the screen downward)

I would like to have a UINavigationController that hovers on the current screen instead of "translating" the screen downward to make way for it.
Currently my implementation goes like this:
UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonSystemItemCancel target:self action:#selector(backButtonTapped)];
[self.navigationItem setBackBarButtonItem:backButton];
So that what happens is everytime I show the navigationItem, it slides itself downwards into the screen, translating the entire screen. And then when I hide it, it slides out, pulling back the entire screen up. I'd like it to hover instead, i.e. the position of the screen remains untouched. Thanks!
As per question, you want to animate screen when we push screen from navigation controller. I have done in my project. Steps as below
1) When you push view controller from Navigation Controller means, You have to animate current view controller when we push. code as below
(void)viewWillDisappear:(BOOL)animated {
[UIView beginAnimations:#"animation2" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[super viewWillDisappear:animated];
}
2) If you want to pop from second view controller to first view controller means, you have type same code in second view controller.. You can change animation transition side by modify this method argument setAnimationTransition

Display Modal View Controller over detail view in UISplitViewController

I have a UISplitViewController in an iPad app. When something is selected from the table I want to fade in a modal view controller over the detail view. I can present it without a problem, but for some reason I can't get it to match the frame of the detail view. I would like it to stick to the detail view controller frame on rotation as well. Does anyone have any experience with this? This is my code to display. The detail view controller reference is set in the app delegate and passed down the table controllers.
QuestionViewController_iPad *questionView = [[[QuestionViewController_iPad alloc] initWithNibName:#"QuestionViewController_iPad" bundle:nil] autorelease];
questionView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
// Not quite
questionView.modalPresentationStyle = UIModalPresentationCurrentContext;
questionView.questionQuizCon = [QuestionQuizConnection firstQuestionForQuiz:quizCatCon.quiz];
// Maybe something like this?
[self.detailViewController presentModalViewController:questionView animated:YES];
When the modal view presents, it matches the size of the detail view controller, but it doesn't but it sits on the top left of the screen behind the master view controller. It also doesn't resize on rotation. I have the springs and struts set to auto size and fill. The height changes on rotation but it won't fill the width.
I couldn't get this to look right any way I tried it so I ended up just using view transitions to make it look like pages being torn off a notebook. That looks better anyway.
// Transition the view on as a subview.
[UIView transitionWithView:self.detailViewController.pageView duration:1.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^ {
questionView.view.frame = CGRectMake(0, 0, self.detailViewController.pageView.frame.size.width, self.detailViewController.pageView.frame.size.height);
[self.detailViewController.pageView addSubview:questionView.view];
// Watch this one
self.detailViewController.currentQuestionViewController = questionView;
}
completion:nil];
After [self.detailViewController presentModalViewController:questionView animated:YES]; you should set center property and/or frame of questionView. Be sure that you set it after presenting modal view.

View drawn under status bar

So i managed to load another view when someone presses a button ,but it loads it to high. `i don't know why this happens. The difference is exactly the top bar hight. This is my code:
In the delegate i have:
- (void)flipToAbout {
AboutViewController *aaboutView = [[AboutViewController alloc] initWithNibName:#"AboutViewController" bundle:nil];
[self setAboutController:aaboutView];
[aaboutView release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES];
[homeController.view removeFromSuperview];
[self.window addSubview:[aboutController view]];
[UIView commitAnimations];}
In the about view i didn't change anything.Please tell me what is the problemm .Thanks.
The problem is that you're adding your view directly to the window without accounting for the navigation bar. Normally, if you have a navigation bar, you use a navigation controller to manage your view controllers. Pushing a view controller onto the nav controller's stack causes the nav controller to add that view controller's view to the window for you, and you don't have to worry about the nav bar. Since you're doing it by hand, though, you'll want to reposition the view after you add it to the window.
Note that this problem doesn't have anything to do with nibs except that you load your view from a nib. The same thing would happen if you created the view programmatically.

Resources