iPhone animations - animating one things causes other things to be animated - iphone

I've animated moving a UIView as follows:
CGRect rightPop = CGRectMake(167, 270, 142, 73);
[UIView beginAnimations:nil context:NULL];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.4];
[rightToast setFrame:rightPop];
[UIView commitAnimations];
The animation occurs just fine, but it causes other parts of the app to become animated (eg, navigation bars etc).
Does anyone know how I can stop the other animations?

It's happening because animation blocks can be nested. You're opening two of them via beginAnimations, but only closing one via commitAnimations. The second animation block is still open, so extra animations are not surprising. I don't know why you're calling beginAnimations twice, it's not necessary. Drop that and things should work normally.

Related

FlipView Transition

I'm currently designing an app that pulls map data from a service and renders them as pins on the MKMapView. In addition, my application has been designed using storyboards where each scene is embedded within a navigation controller. The feature I'm working on requires me to give the user the ability to toggle between a map view and table view for a given result set. To provide this functionality I've included a bar button item in the toolBar which (when pressed) should flip the current view out and a second view in.
So far I've been trying to the following code but to no avail:
MapListViewController *map = [[MapListViewController alloc]init];
[UIView beginAnimations:#"flip animation" context:nil];
[UIView setAnimationDuration:3.0];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:map.view cache:YES];
[self.mapView removeFromSuperview];
[self.view addSubview:map.view];
[UIView commitAnimations];
I originally got this approach from here but it doesn't seem to be working for me.
A couple more things to note:
The flip view transition should only change the view currently displayed within the top and bottom navigation bars.
Presenting the new view modally isn't an option because I will lose site of my navigation controller.
The view/view controller responsible for displaying the result set in a list format (i.e. UITableView) is contained within a single xib file where as the rest of the application sits within a storyboard.
Question
What is wrong with my current implementation? How should it be modified?
I haven't used your method but I did implement flipping some views using a UIView class method. It was very easy and straightforward. Refer to the docs for other options.
[UIView transitionFromView:self.firstVC.view toView:self.secondVC.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
// add any completion code here if needed.
}];
Check this links may help you
Flip View Iphone
how to implement an iPhone view transition animation with both flipping and scaling?
Hope it helps you . Thanks!!
Hi implementing some thing like this should help you
To Push use this..
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[navigationController pushViewController:viewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:navigationController.view cache:NO];
[UIView commitAnimations];
For Pop use this
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[navigationController popViewControllerAnimated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:navigationController.view cache:NO];
[UIView commitAnimations];

UIView animation end

I am using UIView animation in my app:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
//do some animation
[UIView commitAnimations];
Now, there is a possibility that the animation would take a couple of seconds to finish. So, is there a way to know when the animation has ended?
Use the latest block-based animation methods provided by apple as:
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
//animation block
}
completion:^(BOOL finished){//this block starts only when
//the animation in the upper block ends
//so you know when exactly the animation ends
}];
The method you have used will be deprecated soon...
I haven't uses this myself yet, but there is a method setAnimationDidStopSelector that allows you to define a selector that should be called when an animation has finished.
Also see the documentation at Apple for UIView.
There is also an example on Ray Wenderlich's site

How do you code nested UIView animations?

I need to perform 9 animations where each animation starts after previous one. So I have huge gigantic piece of code with UIView animateWithDuration calls. It really looks ugly :) Is there any better options than making 8 additional methods and nesting them?
Core Animation is your friend.
http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html
Or you can write all of these 9 steps into one method by using block-based animation method. But it still dosen't look beautiful and iOS 4 is requied.
You can still use the UIView animation or coreanimation and use the delegate call back i.e:
[UIView beginAnimations:#"fadeIn" context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDidStopSelector:#selector(finishAnimation:finished:context:)];
[UIView setAnimationDelegate:self];
theview.alpha = 1;
[UIView commitAnimations];
then in the finishAnimation method you can call another animation.

Animate a UIButton from one image to another

I noticed in the Jamie Oliver app, when you click one of the buttons, it goes from one size to another in a smooth transition. Does anyone know how this is done? I tried using some of the UIView animations, but none of them satisfies my needs.
UIAnimations alone can not give you that effect.. You need to couple them with transformations to achieve the effect that you are talking about. Try it in the following way. You will get what you need...
[UIView beginAnimations:#"Zoomin" context:nil];
[UIView setAnimationDuration:0.25];
starImage.transform=CGAffineTransformMakeScale(2.5, 2.5);
[UIView commitAnimations];
[UIView beginAnimations:#"Zoomout" context:nil];
[UIView setAnimationDuration:0.25];
starImage.transform=CGAffineTransformMakeScale(1, 1);
[UIView commitAnimations];
I believe animation blocks are the preferred method for animating views now.

Troubles with UIView, animateWithDuration and beginFromCurrentState

I have a custom view that has to track the user's location. I put the following code in touchesBegan, as well as in touchesMoved:
[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
cursorView.center = locationOfTouch;
} completion:^(BOOL finished){}];
It seems fairly straightforward to me. I'd expect the view to always animate to the user's current location, even if that location is changed and the view is still animating (because of the beginFromCurrentState option).
Yet, each animation finishes completely. They don't 'transition' to the new animation, no they finish first, then they start the new animation.
I tried adding this line in touchesMoved:
[cursorView.layer removeAllAnimations];
Doesn't do anything. No animation is cancelled. Any ideas?
with [cursorView.layer removeAllAnimations]; you access the layer of the view but you have set the animation not to the layer but the view directly.
Try:
[UIView beginAnimations:nil context:NULL]
[UIView setAnimationDuration:0.2];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
cursorView.center = locationOfTouch;
[UIView commitAnimations];
and leave out the removeAllAnimations and it should transition from current state.
Looks like this is a derivative of another question you asked that I just answered, but the same idea applies.
You don't need to use blocks to do this. Just wrap your setCenter in a UIView animation. Like this:
[UIView beginAnimations:nil context:NULL]
[UIView setAnimationDuration:0.2f];
cursorView.center = locationOfTouch;
[UIView commitAnimations];
Keep in mind that 0.2 seconds is pretty fast. It may appear to be "jumping" to the position. To confirm, set the duration to something like 2.0 seconds and see if it's animating.
Best regards.
Technically, the view should automatically animate with a default time of 0.25 seconds. That is what the manuals say, however, I'm currently on here because the manuals don't seem to be very accurate regarding animation.
Also, the beginAnimations call is being phased out, you might want to use a CATransaction instead