custom UIView animation in dismissModalViewController - objective-c

Where is the correct place to put custom animation code for dismissing a modalviewcontroller.
I tried putting the following into viewdiddisappear, viewwilldisappear but doesn't behave correctly. Any thoughts? THanks!!
[UIView beginAnimations:#"suck" context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:103 forView:self.navigationController.view cache:YES];
[UIView setAnimationPosition:CGPointMake(260, 431)];
[UIView commitAnimations];

Try this:
UIViewController *myController = [[[MyViewController alloc] init] autorelease];
UIViewAnimationTransition transition = UIViewAnimationTransitionCurlUp; // or whatever effect you want
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:transition forView:[self window] cache:YES];
[navController presentModalViewController:myController animated:NO]; // or dismissModalViewController in your case
[UIView commitAnimations];

I think I figured it out. I followed the example in:
http://developer.apple.com/library/ios/#samplecode/BubbleLevel/Introduction/Intro.html
Basically removed the second view from superview and inserted the first view back in. The transition works correctly afterwords.
THanks for the help.

Related

Can't remove subview from superview-Xcode6

I added a view (displayTapeView)to the superview via Storyboard and it's working fine. But when I want to remove displayTapeView when clicking the "Back"button on the displayTapeView. It doesn't work. My current code is as below:
- (IBAction)tapeButtonPressed:(id)sender {
self.displayTapeView.hidden=NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
//[[self displayTapeView] removeFromSuperview];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.displayTapeView cache:YES];
self.displayTapeView.layer.masksToBounds=NO;
self.displayTapeView.layer.shadowOffset=CGSizeMake(-15.0,20.0);
self.displayTapeView.layer.shadowRadius=5.0;
self.displayTapeView.layer.shadowOpacity=0.5;
//[[self view] addSubview:_displayTapeView];
[UIView commitAnimations];
}
- (IBAction)backButtonPressed:(id)sender {
[[self displayTapeView] removeFromSuperview];
}
What I want to do is when "Back" button is clicked, the displayTapeView is removed and the superview is shown.
Thank you in advance!
self.displayTapeView.hidden = YES;

iOS transition animation for pushViewController

I have an AppDelegate, which owns a window, and from there on, A main view, from which when I go to the next view, I push the new view in order to use the same Navigation Controller and toolbar:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
self.appview = [[AppointmentView alloc] initWithNibName:#"AppointmentView" bundle:[NSBundle mainBundle]];
#synchronized(self.MahAppntmnts){ // Set the view's appointment
[appview setMyAppointment:[[MahAppntmnts MyAppointments] objectAtIndex:indexPath.section]];
}
[super addChildViewController:self.appview];
AppDelegate *del = (AppDelegate *)[UIApplication sharedApplication].delegate;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[del.navigationController pushViewController:self.appview animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
}
Now this works fine for switching views, but when I'm trying to go back, I get the same boring flip transition.
I tried setting on my AppView's viewWillDissapear delegate method:
-(void) viewWillDisappear:(BOOL)animated
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];
[super viewWillDisappear:animated];
}
This seems to work for when I go back to the previous view, but when I try to transition to new views (using the same method as before) they either not appear, or I flip by to the same view. So I'm guessing that this code should not be on viewWillDissapear, or that I am doing something wrong...
Well I found the solution, problem was my miss-conception to "whom" the animation belonged to. I added the code found in viewWillDissapear (located in the pushed view), to the viewWillAppear delegate of the view that did the pushing in the first place (the code found in accessoryButtonTappedForRowWithIndexPath), so that the controlling view initiates the animation when pushing another view, and when another view navigates back to it, the reverse animation is displayed. Solved all problems and works like a charm.

View slides up instead of curling with Model View Controller

SignView *tempVC = [[SignView alloc] initWithNibName:#"SignView" bundle:Nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView setAnimationDelay:0.5f];
[UIView setAnimationDuration:2.0f];
[UIView commitAnimations];
[self presentModalViewController:tempVC animated:YES];
[tempVC passDataWithString:button2.titleLabel.text andColor:currentlySelectedColor isNightModeOn:nightMode.on];
The view slides up instead of Curling up.
What am I doing wrong?
To set the transition style of a modal view controller, set it's modalTransitionStyle property.
self.modalTransitionStyle = UIModalTransitionStylePartialCurl;
Also note that some transition styles don't look right on the simulator, but should be fine on the device.

Trying to fade in a UIView without success

I am trying to fade in a UIView as a subview of my main view. The UIView I am trying to fade in has the dimensions of 320x55.
I setup the view and a timer;
secondView.frame = CGRectMake(0, 361, 320, 55);
secondView.alpha = 0.0;
[self.view addSubview:secondView];
[NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:#selector(fadeView) userInfo:NO repeats:NO];
The timer triggers the following code;
secondView.alpha = 1.0;
CABasicAnimation *fadeInAnimation;
fadeInAnimation = [CABasicAnimation animationWithKeyPath:#"opacity"];
fadeInAnimation.duration = 1.5;
fadeInAnimation.fromValue = [NSNumber numberWithFloat:0.0];
fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
[fadeInAnimation setDelegate:self];
[secondView.layer addAnimation:fadeInAnimation forKey:#"animateOpacity"];
My secondView is connected in Interface Builder and responds to other messages but I can't see anything happening on screen.
Can anyone please help me figure out what's going on here?
Thanks,
Ricky.
In reply to a following recommendation:
I'm a bit unsure here. Initially I put this code in (because I see secondView as an instance of UIView?):
[secondView beginAnimations:nil context:NULL];
[secondView setAnimationDuration:0.5];
[secondView setAlpha:1.0];
[secondView commitAnimations];
I then tried your suggestion which didn't produce warnings or errors, but it still does brings nothing to the surface:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[secondView setAlpha:1.0];
[UIView commitAnimations];
Thanks! Ricky.
You should be able to do this a bit simpler. Have you tried something like this?
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[secondView setAlpha:1.0];
[UIView commitAnimations];
it seems to me that one thing you're missing is that your view may already have an alpha of 1.0. make sure the alpha is 0 (or whatever you desire it to be) prior to the animation call.
i prefer to use block animations for this. it's cleaner and more self-contained.
secondView.alpha = 0.0f;
[UIView animateWithDuration:1.5 animations:^() {
secondView.alpha = 1.0f;
}];
This won't answer your question if you insist on using CoreAnimations, but for iPhoneOS it's much easier to use animation blocks for UIView animations.
secondView.alpha = 0.0f;
[UIView beginAnimations:#"fadeInSecondView" context:NULL];
[UIView setAnimationDuration:1.5];
secondView.alpha = 1.0f;
[UIView commitAnimations];
Also, you can invoke a delegate in delayed time with
[self performSelector:#selector(fadeView) withObject:nil afterDelay:0.5];
Here is also a good alternative with many options and easy to use.
[secondViewController.view setAlpha:0.0];
[UIView animateWithDuration:1.5
delay:0.0
options:UIViewAnimationOptionCurveEaseIn // See other options
animations:^{
[secondViewController.view setAlpha:1.0];
}
completion:^(BOOL finished) {
// Completion Block
}];

bottom up animation using Pushviewcontroller?

I am new to Iphone SDK.i am using following code.but the animation happens
from Right to Left when i click this button.i want to do fro botton to Up
- (IBAction)clickedsButton:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:settingsController animated:TRUE];
[UIView commitAnimations];
}
setAnimationTransition supports only Two ...
1)UIViewAnimationTransitionFlipFromLeft
2) UIViewAnimationTransitionFlipFromRight..
any help please? i used following, but it is not working
settingsController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController pushViewController:settingsController animated:YES];
What you're looking for is
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated;
SWIFT 3
self.present(newViewController, animated: true, completion: nil)