UIView transitionFromView change view heigh - ios

I am using this code to change between 2 UIView:
UIViewAnimationOptions animationType = UIViewAnimationOptionTransitionFlipFromLeft;
[UIView transitionFromView:self.playlistTableView toView:self.playerView duration:0.5 options:animationType completion:^(BOOL finished){
[self.containerView sendSubviewToBack:self.upperView];
[self.containerView sendSubviewToBack:self.playerView];
self.isPlaylistVisible = !self.isPlaylistVisible;
isControlsHidden = NO;
}];
And i noticed a strange behavior, that when i made the flip the height of the self.playerView loosing 20px and after one second it's increase back to the normal frame size.
I try to change the animationType to UIViewAnimationOptionLayoutSubviews and now when i change between the view this behavior is not occur.
Any idea what can be the issue?

Please try this code.
[self.upperView setHidden:YES];
[self.playerView setHidden:NO];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationDuration:1.0];
[UIView commitAnimations];
[containerView addSubview:self.playerView];
For getting reverse case
[self.upperView setHidden:NO];
[self.playerView setHidden:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationDuration:1.0];
[UIView commitAnimations];
[containerView addSubview:self.upperView];

Related

About 'beginAnimations' and 'commitAnimations'

I added in the button click event:
[UIView beginAnimations:nil context:nil];
sender.titleLabel.font = [UIFont systemFontOfSize:18];
[UIView commitAnimations];
The animation is not working. But if I remove [UIView commitAnimations];, the animation works. Why?
If I don't add [UIView commitAnimations];, what will happen?
Why you are not using this for view animations?
[UIView animateWithDuration:1.0 animations:^{
// place your animations code here
}];
Note: please visit this url and see the section What can be animated. Only few properties can be used for animations
https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html
Try this, it will help. In the example below, viewObject may be label in your case.
[UIView animateWithDuration:1.0 animations:^{
viewObject.transform = CGAffineTransformMakeScale(1.5, 1.5);
}];

How to animate a UILabel after another

I currently animate two UILabel as such:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[_temperatureLabel setAlpha:1];
[_tempDescriptionLabel setAlpha:1];
[UIView commitAnimations];
However, I want to show the first label _temperatureLabel then once that is done animating (or maybe halfway through) start animating the second label _tempDescriptionLabel.
as I said I'll answer:
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
//set alpha 1 for first UILabel
_temperatureLabel.alpha = 1;
} completion:^(BOOL finished){
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
//when finished enter here
//set alpha 1 for second UILabel
_tempDescriptionLabel.alpha = 1;
} completion:^(BOOL finished){
}];
}];
remember to add QuartzCore framework, and add #import <QuartzCore/QuartzCore.h>
For doing halfWay or any other mid way time,
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[_temperatureLabel setAlpha:1];
[UIView commitAnimations];
[self performSelector:#selector(halfWayStart:) withObject:nil afterDelay:1.0];
-(void)halfWayStart:(id)object{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[_tempDescriptionLabel setAlpha:1];
[UIView commitAnimations];
}
so, changing the afterDelay time value in performSelector call will help you to start other animation any time.

IOS: animation deceleration for a button

In my app I move a button with this code:
[UIView beginAnimations:#"timerView" context:nil];
[UIView setAnimationDuration:0.5];
[timerView setCenter:CGPointMake(967, 80)];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
but I want that the animation decelerate first to arrive to the point, how can I do it?
Add this line,
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];

Switch View with animation

I must change a view. In a view I've a button with this code:
FormazioneViewController *formazioneC = [[FormazioneViewController alloc] initWithNibName:#"FormazioneView" bundle:nil];
self.formazioneViewController= formazioneC;
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self viewWillDisappear:YES];
[self viewDidDisappear:YES];
[self.view addSubview:formazioneViewController.view];
[formazioneViewController viewWillAppear:YES];
[formazioneViewController viewDidAppear:YES];
[UIView commitAnimations];
and I add a superview, now i must return in this view and i use a button with this code:
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self viewWillDisappear:YES];
[self viewDidDisappear:YES];
[self.view removeFromSuperview];
[****** viewWillAppear:YES];
[****** viewDidAppear:YES];
[UIView commitAnimations];
What is the object where i must call the viewWillAppear and ViewDidAppear method??
Thanks
Sorry for my bad english!
Have you Written this method,
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}

IOS: problem with alpha

I have this code, where successview start with alpha = 0.00
- (void) startAnimation{
//immediately
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3];
[successView setAlpha:1.00];
[UIView commitAnimations];
//in three seconds
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3];
[successView setAlpha:0.00];
[UIView commitAnimations];
}
in this way, in first animation (alpha 0.00 to 1.00), it don't happen in 3 seconds but immediately, instead in the second animation (alpha 1.00 to alpha 0.00) it happens in 3 seconds
if I write only firts animation:
- (void) startAnimation{
//in three seconds
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3];
[successView setAlpha:1.00];
[UIView commitAnimations];
}
it happens in 3 seconds, why in the forst example it don't happen?
- (void)startAnimation
{
[UIView beginAnimations:#"successAnimationPart1" context:nil];
[UIView setAnimationDuration:3];
[UIView setAnimationDelegate:self];
[successView setAlpha:1.00];
[UIView commitAnimations];
}
And add this animation delegate method:
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
if ([animationID isEqualToString:#"successAnimationPart1"]) {
// when first animation is done, call second
[UIView beginAnimations:#"successAnimationPart2" context:nil];
[UIView setAnimationDuration:3];
[UIView setAnimationDelegate:self];
[successView setAlpha:0.00];
[UIView commitAnimations];
}
}
You can try to set animation delay for your 2nd animation (note that using this api is discouraged and you should use block-based animateWithDuration:delay:options:animations:completion: animation if you're targeting iOS4.0+):
...
[UIView setAnimationDelay:3.0];
...
But if you just want to change view's alpha to 1 and revert it back you can use just your 1st animation but make it autoreversing:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3];
[UIView setAnimationRepeatAutoreverses:YES];
[successView setAlpha:1.00];
[UIView commitAnimations];

Resources