About 'beginAnimations' and 'commitAnimations' - ios

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

Related

UIView page curl animations isn't working with blocks

I'm trying to convert working UIView animations to using blocks. Aside from the completion callback, I don't see what's different about them. Could someone clarify something I might be missing?
This works as expected
[UIView beginAnimations:#"Curl" context:nil];
[UIView setAnimationDuration:.15];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.storyTextView cache:YES];
self.storyTextView.text = text;
[UIView commitAnimations];
This does change the page's text, but no animation is show, it's just an instant transition.
UIViewAnimationOptions curl = UIViewAnimationOptionTransitionCurlUp;
[UIView animateWithDuration:.15 delay:0 options:(UIViewAnimationOptionCurveEaseInOut | curl) animations:^{
self.storyTextView.text = text;
} completion:^(BOOL finished) {
if (finished){
// pass
}
}];
Moreover, setting delay in the blocks style animation does nothing to affect the instant transition, it just runs the completion block after the delay.
You'll want to try UIView's transitionWithView instead:
UIViewAnimationOptions curl = UIViewAnimationOptionTransitionCurlUp;
[UIView transitionWithView:self.view duration:0.15 options:(UIViewAnimationOptionCurveEaseInOut | curl) animations:^{
self.storyTextView.text = text;
} completion:nil];

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 - Moving view does not animate

I have toolbar on my view and I want to move it with animation, but the animation does not work, the toolbar move quickly to the new position. I use it:
[UIView animateWithDuration:2.0f animations:^{
[self.view layoutIfNeeded];
self.toolbarBottomLayoutConstraint.constant = editing ? 0 : -44;
}];
Does anybody know why?
I've tried just changing animation block sentences and it worked for me:
[UIView animateWithDuration:2.0 animations:^{
self.bottomMargin.constant = editing ? 0 : -44;
[self.view layoutIfNeeded];
}];
Why don't you do something like this?
[UIView animateWithDuration:2.0f
animations:^{
yourView.center = CGPointMake(yourView.frame.size.width/2, -44);
} completion:^(BOOL finished) {}];

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

UIView Flip Animation Too Fast - iOS

I tried animating a sequence of UIViews from a mutable array to simulate this animation
for(int k = 0; k< [imageViewCarrier count] ; k++){
UIView *transformingView = [imageViewCarrier objectAtIndex:k];
[UIView animateWithDuration:30.0 animations:^{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:30.0];
[UIView setAnimationDelegate:self];
[UIView transitionFromView:transformingView toView:splicedImageView duration:3 options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL];
[UIView commitAnimations];
}completion:^(BOOL finished){
NSLog(#"Transition done");
}];
}
The animation seems to be too fast. Any suggestions on this. Did search some documentation but couldn't figure it out. Some help would be greatly appreciated!
Hm, I think you might be doing it the wrong way. If memory serves me, when using [UIView animinateWithDuration:animiations:completion:], you shouldn't call [UIView beginAnimations:nil context:NULL]; and [UIView commitAnimations]; or setAnimationDelegate: or setAnimationDuration: for that matter, since they are the old way of animating views that you had to use before the block-based methods were introduced.
I'd try leaving those out and see what happens. Also, note that the duration parameter is in seconds, so 30.0 seems a bit too long.
And just a style note: the "proper" Objective-C way to iterate through a collection is as follows:
for(UIView* view in imageViewCarrier){
[view doSomething];
}

Resources