Slide UITableView Off Screen? - objective-c

I am trying to animate my UITableView sliding off the screen, I have tried this below without success:
-(void)slideTableViewOffScreen
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
stageSelectionTable.frame = CGRectMake(stageSelectionTable.frame.origin.x - stageSelectionTable.frame.size.width, stageSelectionTable.frame.origin.y, stageSelectionTable.frame.size.height, stageSelectionTable.frame.size.width);
[UIView commitAnimations];
}
Any ideas why it might not work, or what I need to do for this animation to work? When that code is called, nothing happens.

Turns out this code works without any weirdness:
-(void)slideTableViewOffScreen
{
CGRect newFrame = stageSelectionTable.frame;
newFrame.origin.x -= 130;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
stageSelectionTable.frame = newFrame;
[UIView commitAnimations];
}

Related

setAnimationDidStopSelector: not getting called

I know this question gets asked a lot but i have tried all the other answers and i can't figure out why the animation stop selector does not get called. Here is the code:
-(void) moveImage:(UIImageView *)image duration:(NSTimeInterval)duration curve:(int)curve x:(CGFloat)x y:(CGFloat)y annKey:(NSString *) annKey{
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDidStopSelector:#selector(animationFinished:finished:context:)];
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
image.transform = transform;
[UIView beginAnimations:annKey context:NULL];
[UIView commitAnimations];
}
This is the main animation function that gets sent all the correct parameters.
- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context
{
if ([animationID isEqualToString:#"Burn"])
{
NSLog(#"Animation: %# has finished.",animationID);
}
NSLog(#"This does not get called, why not?");
}
None of my NSLogs display text. What am i doing wrong?
You need tho do -
[UIView beginAnimations:annKey context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationFinished:finished:context:)];
// Now define rest.
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
image.transform = transform;
[UIView commitAnimations];
Not sure what the problem is, but you really shouldn't be using beginAnimations/commitAnimations. Instead, use block animations. You define the completion code directly in the completion portion of the call.
[UIView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
// animation code
}
completion:^(BOOL finished){
// completion code
}];

fade in, fade out animation to uilabel

i have a label that i want to fade in and then to fade out.
here is my code:
-(void) fadein
{
scoreLabel.alpha = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:2];
scoreLabel.alpha = 1;
[UIView commitAnimations];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
}
-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2];
scoreLabel.alpha = 0;
[UIView commitAnimations];
}
from this code i get this situation: my label is fade in and then i don't see the fadeout animation.
how can i fix it?
-(void) fadein
{
scoreLabel.alpha = 0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//don't forget to add delegate.....
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:2];
scoreLabel.alpha = 1;
//also call this before commit animations......
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
}
-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2];
scoreLabel.alpha = 0;
[UIView commitAnimations];
}
The call to setAnimationDidStopSelector should be before commit the animations:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:2];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
scoreLabel.alpha = 1;
[UIView commitAnimations];

how to animate a UIView same as the working of presentModalViewController ( ie [self presentModalViewController:child animated:YES];)

I am new in ios development, Now i am doing some animation on my application.In my application has one menu on the bottom of main view and have two button one for hide the menu and other for show the menu .My needs is the show and hide function of menu is working like
the [self presentModalViewController:menuView animated:YES]; and [self dismissModalViewControllerAnimated:YES]; function(ie. click the show button ,pop the menuView from the bottom of main view and click the hide button ,move down the menuView ) . I know the basic animation like:
[UIView beginAnimations:#"ShowHideView" context:nil];
[UIView setAnimationCurve:UIViewAnimationOptionOverrideInheritedCurve];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[menuView setAlpha:0];
[UIView commitAnimations];
If any body know ,please help me.
When you tap showMenuView, do as following,
- (IBAction)showView:(id)sender
{
[self.view addSubview: menuView];
CGRect rect = menuView.frame;
rect.origin.y = 480;
menuView.frame = rect;
[UIView beginAnimations:#"ShowView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
rect.origin.y = 0;
menuView.frame = rect;
[UIView commitAnimations];
}
And to hide,
- (IBAction)hideView:(id)sender
{
CGRect rect = menuView.frame;
[UIView beginAnimations:#"HideView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
rect.origin.y = 480;
menuView.frame = rect;
[UIView commitAnimations];
}
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[menuView removeFromSuperview];
}

I can't animate UIView's border color

I try to make fade in/out effect for UIView border but it does'nt work.
When try to do the following effect for background color it works perfectly.
Here is a code I developed:
[UIView animateWithDuration:3.0f
animations:^ {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
self.layer.borderColor = [[UIColor redColor] CGColor];
self.layer.borderWidth = 1.5f;
[UIView commitAnimations];
}
completion:^(BOOL finished){
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.8];
self.layer.borderColor = [[UIColor whiteColor] CGColor];
self.layer.borderWidth = 1.5f;
[UIView commitAnimations];
}];
According to the answer to my question you can't animate CALayer properties in a UIView block.

UIView animation change size of button

I started trying to recreate the buy button from the app store which requires a 2-stage click to buy something. I to animate the button expanding. So far I have this
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
sender.autoresizesSubviews = NO;
sender.clipsToBounds = NO;
sender.frame = CGRectMake(63,326,200,37);
[UIView commitAnimations];
which just causes the button to become larger, it doesn't animate at all. Have I done something wrong or has anyone else implemented this type of button behaviour?
EDIT:
- (IBAction) buyButtonAction: (UIButton *) sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationDelay:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
sender.clipsToBounds = NO;
sender.frame = CGRectMake( CGRectGetMinX( sender.frame) - 30, CGRectGetMinY(sender.frame), 200, 37);
[sender setTitle:#"Touched Touched Touched" forState:UIControlStateNormal];
[UIView commitAnimations];
}
Are you targeting an iOS that doesn't support Blocks?
I've implemented a "button animates on touch" using the following nauseatingly simple code.
[UIView animateWithDuration:0.5 animations:^{
self.navigationItem.rightBarButtonItem.title = #"Quoting...";
}];
Alternatively, this code seems to work as well to animate a button on touch, if you can't support blocks (it also includes the blocks commented out if you go that route):
-(IBAction) clicked:(UIButton*)sender{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//[UIView animateWithDuration:2.5 animations:^{
sender.autoresizesSubviews = NO;
sender.clipsToBounds = NO;
sender.frame = CGRectMake(63,326,200,37);
//sender.frame = CGRectMake( CGRectGetMinX( self.theButton.frame) - 100, CGRectGetMinY(self.theButton.frame), 300, 40);
//[sender setTitle:#"Touched Touched Touched" forState:UIControlStateNormal];
//}];