View drawn under status bar - ios

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.

Related

transitionFromView with UIViewAnimationOptions similar like navigating with UINavigationController

I'm using a similar approach described here for the animation from one view controller to another:
UIWindow *window = (UIWindow *)[[UIApplication sharedApplication].windows firstObject];
[UIView transitionFromView:window.rootViewController.view
toView:vc.view
duration:0.65f
options:UIViewAnimationOptionTransitionCrossDissolve // transition animation
completion:^(BOOL finished){
window.rootViewController = vc;
}];
Looking into the UIViewAnimationOptions I didn't found an option for the default animation, which occurs when doing the same with UINavigationController.
Is it possible to get the same animation behavior (moving the view left)? How?
I tried it with this animation:
[UIView animateWithDuration:0.65 animations:^{
view.transform = CGAffineTransformMakeTranslation(-view.frame.size.width, 0);
} completion:^(BOOL finished) {
// do something
}];
but while translating to the new view the background is completely black instead of bringing the other view controller in.
Now I'm doing it in a different way. I start with my navigation controller and its root view. Then I push another view controller on the stack. In viewDidAppear of this new view controller I'm removing the first view controller from the navigation stack. One downside: You can see the back button for a short time.
The animation solution I tried will need the other view controller animated in. Also I had problems with views which very not layout correctly (because of edgesForExtendedLayout).

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
}];

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

How do I draw main view underneath my UINavigationBar so when the bar shows/hides, the view is unaffected?

Here's the situation:
I am making an app for iPad w/ iOS 6 using Autolayout along with UINavigationController. What I am trying to do is:
Segue from one view controller to the next with a standard push segue.
When I arrive at the new view controller, hide the nav bar with animation.
As the nav bar hides, I want my view to not shift at all. In fact, I want my view to effectively be drawn underneath the nav bar from the beginning, so I'm left with no shifting or movement of content and no black bars. For reference, this is what happens in the Amazon Kindle app when you go into a book.
With my current code, the contents of my view shift up to fill in the void left by the UINavigationBar.
I've tried force-setting the frame of my UIViewController's view and my UINavigationController's view to the entire iPad screen in the viewWillAppear method of my viewcontroller but no dice. I've experimented w/ Constraints in Autolayout but that also didn't get me to where I wanted to go.
Any help you can give would be great!
Try following before animating the navigation bar:
self.navigationController.navigationBar.alpha = 0.99f;
I didn't try this but this should work.
Looks like you need to add custom navigation bar in your new view and animate it to disappear.
I think, hiding original Navigation bar of Navigation Controller without shifting the view is not possible.
Rather add UINavigationBar to xib file, bind it to IBOutlet uiNavigationBar and try following code
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{
CGRect f = self.uiNavigationBar.frame;
f.origin = CGPointMake(f.origin.x, f.origin.y - 44);
self.uiNavigationBar.frame = f;
} completion:^(BOOL finished) {
NSLog(#"done");
}];
}

Empty table rows becomes transparent right before page curl transition

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?

Resources