Autolayout - Compressing UINavigationController at the same time as pushing a new view controller - ios

I am working on an iOS app. The root view controller contains a UINavigationController which wraps up the main contents of the app, and a footerViewController (audio player) that will compress the main content when it animates up into view.
I’m using auto layout to show and hide this footer like so:
_footerVisibleConstraints = [… #“V:|[navControllerView][footerView(==90)]|" …];
_footerHiddenConstraints = [… #“V:|[navControllerView][footerView(==0)]|" …];
Generally this works well. But I’m struggling with one issue. I have a situation where I need to push a new view on the UINavigationController stack and animate my footer into view the same time:
[self.view layoutIfNeeded];
[UIView animateWithDuration:1.5f animations:^{
[[self view] removeConstraints:_footerHiddenConstraints];
[[self view] addConstraints:_footVisibleConstraints];
[[self view] layoutIfNeeded];
}];
[navigationController pushViewController:newViewController animated:YES];
The problem in this situation is that newViewController is animating in snapped to it's final (compressed) state, and not beginning from the full starting height of the view. So there is a gap at the bottom while the footer animates in.
I’ve slowed down the animation and posted a video here to demonstrate what I am describing.
Also, notice how when I pop back to the root view controller the content in the UINavigationController isn’t compressed either.
So, can someone explain to me what’s going on here? Is there a way to accomplish what I am after?

Just add a variable to the .h of your VC to stipulate whether the footer needs to open or not. Then add the footer animation to the didAppear method with a check on the variable. This will result in performing the actions in the order you want them to happen.
If you want both animations to happen at the same time you will need to subclass a segue and add a custom animation.

Related

UIViewAnimationTransitionFlip and force refresh

I have to do a flip transition between to view with uiwebview. (Flip by the time second webview load url)
My problem are that my second webview stay black till the transition was finish. (no refresh during the transition).
Is there a way to force a loading\refresh during the transition?
[UIView transitionWithView:mysuperview
duration:0.75
options:UIViewAnimationTransitionFlipFromRight
animations:^{
[myview removeFromSuperview];
}
completion:nil];
You would want to look into methods like setNeedsDisplay within the UIView class. I recommend checking out Drawing and Updating the View section of the UIView class which could be found here. Overall, views do not know when they need to refresh themselves so you will need those methods.

uiviewanimation works in ios 7 but gets clipped and offset in ios6

working on moving my app to IOS7, but i'm having a uiviewanimation problem.
Everything works fine in IOS7, but when i use uiviewanimation to "flip" between two views, the view looks wrong during the transition, but fine after. It's higher up, and a part of the bottom of the view is clipped. See attached picture.
When the animation completes, the view "jumps" down to its correct position. I'm at a loss...
the code i use to flip my view is:
newView = [[LocationCrudViewController alloc] initWithNibName:THE_VIEW bundle:nil];
.....
[UIView transitionWithView:self.window duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^ { self.window.rootViewController = newView; }
completion:nil];
Point worth noting - i used to do:
self.window addSubview:currentViewController.view];
as the view animation, and that worked, however i then got the warning message that Application windows are expected to have a root view controller at the end of application launch so i switched to the above code which, again, works fine in IOS7.
I'm reeeaaally hoping someone can help out here.
For those interested, here's what i ended up doing:
My views are defined as per normal (for me), no ios6/7 deltas are needed, in a nib with associated controllers.
I have created a "dummy" view, which takes up the entire screen but has no content.
In my application delegate, i create my dummy view and set it as root:
self.root = [[RootViewController alloc] initWithNibName:ROOT_VIEW_CONTROLLER bundle:nil];
self.window.rootViewController = root;
I can then add and remove subviews as i see fit, like this:
[currentViewController.view removeFromSuperview];
UIView transitionWithView:self.window duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^ {
[self.window addSubview:newViewController.view]; }
completion:nil];
This works great, and it makes my views go under the status bar in both IOS6 and IOS7, just as i want.
Hope this helps somebody.

uitableview with header like instagram user profile

I've been struggling with this for quite a while now.
I have to implement an user profile similar to what Instagram has in their ios app.
When clicking on the first to buttons on that tab bar like thing all the contents downwards from it changes. The tableview that is displayed on the bottom part has dynamic size so they keep account of that also.
I have something implemented where the top part is a UIView with 5 buttons and based on them the bottom part (witch is like a container view) changes content. And these two (top uiview and bottom container view) are part of UIScrollView. But this way I can't get information back in time on the size about the tableview's size that I want to display in the bottom part in order to modify the UIScrollView's size. And I have a feeling this is a flawed way to do it.
I would really appreciate any ideas oh how to implement this king of interaction. Thank you.
I believe it's a headerView on a UITableView or a UICollectionView, depending on which view mode you have selected. When you tap one of the buttons it changes out the UITableView to a UICollectionView or vice versa.
You want to keep track of the current contentOffset for whichever is being displayed (UICollectionView and UITableView are both subclasses of UIScrollView so you will be able to get this from both) and then set the contentOffset on the view you're switching to.
Setup an ivar for the UIView header subclass so you can easily re-use it.
This is what I have. My problem is that I'm mot getting back in useful time the tableview's frame height from the tableview controller to the UserProfileViewController in order to change the latter's scrollview size. I also feel that I'm somehow doing this backwards so any suggestions are more than welcome.
This view has two parts: an upper part and a lower part. The parent view is a scroll view. What I wanted to achieve with this is having a sort of tab bar in the upper part that will controll waht will appear in the lower part.
The upper part has a flip animation when the upper left button is pressed to reveal another view.
The way this is achieved is by having 2 views: a dummy view and the back view. The dummy view has the front view as a child. The front view is the one that containes all the buttons.
The code for this animation is achieved in this way:
- (IBAction)infoButtonPressed:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.hoverView cache:YES];
if ([self.headerView superview]) {
[self.headerView removeFromSuperview];
[self.hoverView addSubview:self.backOfHeaderView];
[self.infoButton removeFromSuperview];
[self.backOfHeaderView addSubview:self.infoButton];
} else {
[self.backOfHeaderView removeFromSuperview];
[self.hoverView addSubview:self.headerView];
[self.infoButton removeFromSuperview];
[self.headerView addSubview:self.infoButton];
}
[UIView commitAnimations];
}
The lower part is made out of a container view that acts as a place holder.
When a button is pressed a different view controller is displayed in the container view.
Each view controller has a container view of it's own. The specific view of that view controller (tableview) is added to it's container view when the controller is loaded. It also makes sure that if the tableview is already added to the container view it will be removed. All this is done in each specific view controller.
In the view controller of the User Profile view there is an instance of the container view and one of a UIViewController that also acts as a placeholder(named currentViewController from now on). When a specific button is pressed it checks if the an instance of the view controller that we want to display already exists. If not it will make one and will set it's tableview's frame to the bounds of the container view. After that it will remove the currentViewController's view from the superview and the currentViewController itself from the parent viewcontroller to make sure that if there is something assigned to these they will not be there. Then it goes and assigns the desired viewcontroller to the currentViewController. It also assigns the desired viewcontroller's containerView instance to the containerview in the parent viewcontroller (the User Profile viewcontroller). At the end it will add the desired viewcontroller as a child to the main viewcontroller (the User Profile viewcontroller) and desired viewcontroller's view to the containerView of the main viewcontroller.
This is the code for one of the buttons:
//Check if there is an instance of the viewcontroller we want to display. If not make one and set it's tableview frame to the container's view bounds
if(!_userWallViewController) {
self.userWallViewController = [[WallViewController alloc] init];
// self.userWallViewController.activityFeedTableView.frame = self.containerView.bounds;
}
[self.userWallViewController.containerView addSubview:self.userWallViewController.activityFeedTableView];
//If the currentviewcontroller adn it's view are already added to the hierarchy remove them
[self.currentViewController.view removeFromSuperview];
[self.currentViewController removeFromParentViewController];
//Add the desired viewcontroller to the currentviewcontroller
self.currentViewController = self.userWallViewController;
//Pass the data needed for the desired viewcontroller to it's instances
self.userWallViewController.searchURLString = [NSString stringWithFormat:#"event/user/%#/", self.userID];
self.userWallViewController.sendCommentURLString = [NSString stringWithFormat:#"event/message/%#", self.userID];
self.userWallViewController.totalCellHeight = ^(float totalCellHeight){
self.userWallViewController.numberOfCells = ^(float numberOfCells){
NSLog(#"The total number of cells: %f", numberOfCells);
NSLog(#"The total cell height: %f", totalCellHeight);
self.scrollView.contentSize = CGSizeMake(320.0, totalCellHeight + 172.0 + 33.0);
CGRect newFrame = self.userWallViewController.containerView.frame;
newFrame.size.height = totalCellHeight + 33.0;
self.userWallViewController.containerView.frame = newFrame;
NSLog(#"Container view: %f", self.containerView.frame.size.height);
NSLog(#"Scroll view: %f",self.scrollView.contentSize.height );
};
};
//Add this containerview to the desired viewcontroller's containerView
self.userWallViewController.containerView = self.containerView;
//Add the needed viewcontroller and view to the parent viewcontroller and the containerview
[self addChildViewController:self.userWallViewController];
[self.containerView addSubview:self.userWallViewController.view];
[self performSelector:#selector(changeScrollView) withObject:self afterDelay:0.5];
//CLEAN UP THE CONTAINER VIEW BY REMOVING THE PREVIOUS ADDED TABLE VIEWS
[self.userFansViewController.userSimpleTableView removeFromSuperview];
[self.fanOfViewController.userSimpleTableView removeFromSuperview];
[self.userPublishedMovellaListViewController.gridView removeFromSuperview];
[self.userPublishedMovellaListViewController removeFromParentViewController];
self.userPublishedMovellaListViewController = nil;
}
I know this answer is over a year late, but I wanted to state my hypothesis on it...just incase it might help someone else later. Im implementing a similar view and came to this conclusion. Anyone is welcomed to correct me if I'm wrong.
I think that perhaps the top view is a header view and the two options that seem like a collection view and a table view are both collection views.
Because the layout of collection views can be fine tuned to the most minute details, I think the view that looks like a table view is just a really specifically designed collection view. And when switching between the views, the collection view's data and properties are being swapped and reloaded.

ios display views and viewcontrollers on part of the screen

I have this bug that I'm struggling with for a few days now. I basically want to make a profile much like Instagram has.
When you click on one of the first two buttons in the upper "tab bar" the content is displayed in the lower part. The upper part of the screen stays the same. I have some UIViewControllers and some UITableViewController. I have like 5 buttons that are suppose to display the viewcontrollers. My problem is that I can display a tableviewcontroller but if I try to display the second and then go back to the first, for instance, it gets stuck to the last one I displayed. I hope this is clear enough. here is the code for displaying the viewcontroller.
- (IBAction)wallButtonPressed:(id)sender
{
if(!_userWallViewController) {
self.userWallViewController = [[WallViewController alloc] init];
self.userWallViewController.activityFeedTableView.bounds = self.containerView.bounds;
}
[self.currentViewController.view removeFromSuperview];
[self.currentViewController removeFromParentViewController];
self.currentViewController = self.userWallViewController;
self.userWallViewController.searchURLString = [NSString stringWithFormat:#"/event/user/%#", self.userID];
self.userWallViewController.containerView = self.containerView;
[self.containerView addSubview:self.userWallViewController.view];
[self addChildViewController:self.userWallViewController];
[self.userWallViewController.view setNeedsDisplay];
[self.userWallViewController viewWillAppear:YES];
}
containerView is an UIView that takes the whole lower part of the screen. currentViewController is a placeholder viewController and userWallViewController is a UITableViewController.
Any kind of help is much appreciate. This is a real bugging situation. Thanks
I was doing a stupid mistake that was hard to identify bu #Matt's suggestion helped.
[self.fanOfViewController.containerView addSubview:self.fanOfViewController.userSimpleTableView];
[self.currentViewController.view removeFromSuperview];
[self.currentViewController removeFromParentViewController];
self.fanOfViewController.containerView = self.containerView;
[self addChildViewController:self.fanOfViewController];
[self.containerView addSubview:self.fanOfViewController.view];
//CLEAN UP THE CONTAINER VIEW BY REMOVING THE PREVIOUS ADDED TABLE VIEWS
[self.userWallViewController.activityFeedTableView removeFromSuperview];
[self.userFansViewController.userSimpleTableView removeFromSuperview];
Each time I was adding a new tableView from it's view controller by pressing the corresponding button I was stacking it in the current's view container. When I was trying to remove the corresponding viewController from the hierarchy and then add it again the viewDidLoad method was not called (it was only called the first time). The was where I had my logic of removing the tableView.
Now I'm also adding it when the button is pressed and remove the other tableViews from the "stack". It may not be the very best way but I do plan to optimize it. I hope this is clear enough and helps anybody that comes across this problem.

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.

Resources