This question already has answers here:
How can I change the animation style of a modal UIViewController?
(4 answers)
Closed 4 years ago.
Hey, just wondering how/if possible to get a UITableView to animate from top to bottom.
The standard way of doing a transition animated the page bottom to top, bu I have an undo button on the page that I navigate to that I want to allow the user to click if they decide to go back... This is my code for the current animation that goes bottom to top.. if you could help me to change it that would be awesome.
- (void)viewDidLoad {
//Title
self.title = #"Advanced Search";
[super viewDidLoad];
//undo button takes you back to main search options
UIBarButtonItem *undoButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemUndo target:self action:#selector(undoButton:)];
self.navigationItem.leftBarButtonItem = undoButton;
}
- (void)undoButton:sender {
RootViewController *rootViewController = [[RootViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[[self navigationController] presentModalViewController:navigationController animated:YES];
[navigationController release];
}
I dont think top to bottom animation is available but you can still do that with UIView animation block.
The only thing you should do is change the frame of the view you are presenting . Initially set it to the top frame like CGRectMake(0,0,320,0) . Then in an animation block change the frame to CGRectMake(0,0,320,480). This will make it look like coming from the top . And you need to do the reverse when hiding it again .
[UIView beginAnimations:#"AnimatePresent" context:view];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
view.frame = CGRectMake(0, 0 , 320, 480);
[UIView commitAnimations];
Hope this helps !!
Related
In my application, I have navigation controller with two view controllers: MainController and DetailController.
In main view controller I have an image view and I want to push DetailController with animation like GarageBand menu when I tap on image view(look to 20 second of this video).
So, question is how to implement fade-in animation.
Here's the code:
//calls on tapping on image
- (void)tapImageView:(UIImageView *)sender {
DetailController *detailController = [[DetailController alloc] initWithNibName:#"controller" bundle:nil];
//configure detail controller
//here comes animation
[self.navigationController pushViewController:detailViewController animated:NO];
[detailController release];
}
I can animate image fading out:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
//sender is UIImageView
sender.frame = self.view.frame;
imageView.alpha = 0;
[UIView commitAnimations];
but anytime I push my DetailViewController to navigationcontroller, that animation doesn't show.
How to implement GarageBand's menu switching animation?
Thanks.
How about using paging with UIScrollView.
I think it is better than using UIView animation.
I need to switch views by swiping with a curl animation for transition.
I tried PageControl (and other approaches -.-), but it's not what I need for several reasons, so I'll go for the GestureRecogntion, but I stuck.
My problem by now is the architecture. There is the firstVC, calling the SecondVC, onto which I add the subviews (of a third VC) to, which should be swipeable. I don't know if it's possible at all to swipe through subviews from another VC or if it's the code or the IB setup that won't do the job (It's my first time with gesture recogntion)
So by now I just loaded 4 dummy subviews when the secondVC loads. My GR-Code (just for the leftswipe, but rightswipe is more or less the same..)
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
NSInteger viewToBeShown = 0;
NSString *nextSubviewStr = [NSString stringWithFormat: #"view%d", (viewToBeShown)];
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft){
if (currentSubview >0) {
viewToBeShown = currentSubview-1;
nextSubviewStr = [NSString stringWithFormat: #"view%d", (viewToBeShown)];
Ubg *nextSubview = [[Ubg alloc] initWithNibName:nextSubviewStr bundle:nil];
[self.view removeFromSuperview];
[self.view addSubview:nextSubview.view];
Could you tell me if that could should basically work (and it's just my IB setup that's not correct)? This is driving me nuts! If you need any other information, just let me know.
Thank you for your time and patience!
This is the code used for curl animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1];
//setting animation for the current view
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:YES];
//Next ViewController to push
nextPage *detailViewController = [[nextPage alloc] initWithNibName:#"nextPage" bundle:nil];
//Push the next viewcontroller to NavigationController
[self.navigationController pushViewController:detailViewController animated:NO];
[detailViewController release];
//Start the Animation
[UIView commitAnimations];
I have a button that, when pressed, presents a view controller to the user. I currently do this using a method like this:
ProjectViewController *myProj = [[ProjectViewController alloc] init];
myProj.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
myProj.modalPresentationStyle = UIModalPresentationFullScreen;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myProj];
[self presentModalViewController:navController animated:YES];
[myProj release];
[navController release];
I would like to present this new view to the user as a growing rectangle from the middle of the screen. What is the best way of doing this?
Cheers
Try the undocumented transition style zoomyIn/zoomyOut
If those are not the ones you are looking for, set the frame of the view to the center of the view with 0 width/height and transform it to it's final size and position. Untested sample code:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.7];
yourview.frame = finalFrame;
[UIView commitAnimations];
I want to fade the whole screen (including navigation bar) to black when a user presses a button on a uinavigationcontroler, before showing a new view. (i don't want to push this new view, for various reasons).
How would I achieve this?
EDIT
Thanks to Mac and Eiko, I have figured it out. Here's the code I used. Not sure if it is optimal, but it does the trick.
// this is called from a programmatically constructed button.
// change (void) to (IBAction) if linking from IB.
- (void)fadeAndShow:(id)sender
{
// blackView is a #property which has been #synthesize-d
// do I really need to alloc and init this?
blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
blackView.alpha = 0.0;
[blackView setBackgroundColor:[UIColor blackColor]];
[self.navigationController.navigationBar.superview addSubview:blackView];
[UIView beginAnimations:#"fadeAway" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDidStopSelector:#selector(showNewScreen:finished:context:)];
blackView.alpha = 1.0;
[UIView commitAnimations];
}
-(void)showNewScreen:(NSString *)animationID finished:(BOOL)finished context:(void *)context
{
// I guess you could fade in somewhere in the new view controller.
// don't know how to fade back in this view tho... viewDidAppear?
NewViewController *controller = [[NewViewController alloc] initWithNibName:#"NewView" bundle:nil];
[self.navigationController setNavigationBarHidden:YES];
controller.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:controller animated:NO];
[blackView removeFromSuperview];
[controller release];
}
Off the top of my head (I haven't actually tested the following at all):
-(IBAction) buttonClicked:(id) sender
{
[UIView beginAnimations:#"myAnimation" context:nil];
[UIView setAnimationDuration:ANIMATION_DURATION];
blackView.alpha = 1.0;
[UIView commitAnimations];
}
Create a UIView in the navigationbar's superview (which I'm assuming is window-sized) that is the same size as the window.
Set that view's backgroundColor to [UIColor blackColor], and its alpha to 0.0.
In your button handler do something like the above (assuming your new UIView is blackView and ANIMATION_DURATION is your desired animation time in seconds).
Then, add your new view on top.
EDIT: too quick for me Eiko! Also, code at the top since the ordered list seems to screw around with the code formatting - sorry the answer reads a little odd.
You can add a black coloured UIView in screen size on top of your current view, and animate its alpha from 0 to 1. When the animation is done, add your new view. You can remove the black one then. Animate from 1 to 0 for the opposite effect - going from black to the content).
I am working to force a view into landscape mode, and have picked up all kinds of cool tips to make this happen, but am stuck on one item that is left on the screen.
I have my XIB file laid out in landscape, and in my code I create the view controller normally:
RedeemViewController *aViewController = [[RedeemViewController alloc] initWithNibName:#"RedeemViewController" bundle:nil];
aViewController.hidesBottomBarWhenPushed = YES;
aViewController.wantsFullScreenLayout = YES;
[[self navigationController] pushViewController:aViewController animated:YES];
Inside the controller viewDidLoad I complete the following:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
[[self navigationController] setNavigationBarHidden:YES animated:YES];
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
}
[UIView commitAnimations];
What I end up with is a perfectly rotated view, with a grey vertical bar on the left side (see pic).
alt text http://taxhelp.net/vert_bar.png
So to the question, how do I get rid of the bar?
Edit: I am pretty sure this is the navigation bar that is not being hidden.
This is a duplicate of another post, with some modified code, the other question was being answered with the bug.
Remove the navigation bar from Interface Builder or see if its being left behind by one of your other controllers.
I lost a few days on a similar problem because I didn't realize that one of my navbars was not being removed when another controller with a nav bar was being pushed onto another controller with a navbar. ;)