Display view controller's view using custom animation iOS - iphone

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

Related

UIView animation transition between views

I need to make an animation that will come in from the right, displaying the new view.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelay:.5f];
[UIView setAnimationDuration:0.5f];
// display view controller
[UIView commitAnimations];
What should I add here??
IF you have navigationController then use
NextViewcontroller *nextView = [NextViewcontroller alloc]initWithNibName#"NextViewcontroller"
bundle:nil];
[self.navigationController pushViewcontroller:nextView animated:YES];
[nextView release];
How about adding the view as a subView to your current view, then set its place to be outside the current visible area. After which you set your animation to change your subViews position to overlap the current view.

Swipe through views with curl 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];

How to create UINavigationController animation top to bottom [duplicate]

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 !!

Custom Transition Between Navigation Controllers

I want to have a custom transition between two navigation controllers. Let's call the first one sourceController and the other one detailNavController.
Here's my code:
NewEntryViewController *viewController = [[NewEntryViewController alloc]
initWithStyle:UITableViewStyleGrouped];
viewController.parentController = self;
UINavigationController *detailNavController = [[UINavigationController alloc]
initWithRootViewController:viewController];
[UIView beginAnimations:nil context:NULL];
[self.navigationController presentModalViewController:detailNavController animated:NO];
[UIView setAnimationDuration:0.4];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:sourceController.view cache:YES];
[UIView commitAnimations];
SourceController was first presented modally, that's why I'm presenting detailNavController modally. The problem with this code is that the animation takes place, but sourceController is still on top of the new detailNavController. What I would like to achieve is to have the animation and then dismiss sourceController and have detailNavController displayed.
I've finally found the solution for this, here's the updated code:
- (void)createNewEntryWithAnimation
{
// before calling this method I dismissed sourceController without animation
NewEntryViewController *viewController = [[NewEntryViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewController.parentController = self;
UINavigationController *detailNavController = [[UINavigationController alloc]
initWithRootViewController:viewController];
[UIView beginAnimations:nil context:NULL];
[self.navigationController presentModalViewController:detailNavController animated:NO];
[UIView setAnimationDuration:0.4];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:viewController.view.window cache:NO];
[UIView commitAnimations];
}
I had to use cache:NO, otherwise the transition wasn't smooth.

Fade to black within a uinavigationcontroller?

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).