UIAnimation not showing - iphone

I have used this code:
[[self.view viewWithTag:100] setTransform:CGAffineTransformMakeScale(0.009, 0.009)];
UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationRepeatCount:0];
[[self.view viewWithTag:100] setTransform:CGAffineTransformMakeScale(1, 1)];
[UIView commitAnimations];
in viewWillAppear of my popup view.
The code works fine on simulator and produces nice effect in which my view appears to grow from center, however on device the animation effect is absent its more like sleep of 0.5 and then all off a sudden view appears.
Since this view is used liberally i don't want to increase duration any help?

Actually the code sample works for me in viewDidLoad and viewWillAppear.Increased the time and animation works fine here.
Why use this method?Apple provides a new and better technique with blocks to do the view animations.
Try this
[[self.view viewWithTag:100] setTransform:CGAffineTransformMakeScale(0.009, 0.009)];
[UIView animateWithDuration:10.5 animations:^{
[[self.view viewWithTag:100] setTransform:CGAffineTransformMakeScale(1, 1)];
}];

Related

non UIView animation: animations not playing sometimes, UIView animation: working fine

Sometimes when I run my app on the device, I guess about 20% of the time, animations such as:
[tableView setEditing:NO animated:YES];
[tableView setContentOffset:rect animated:YES];
and
[viewController0 pushViewController:viewController1 animated:YES];
do not animate but instantly change. But animations such as:
[UIView animateWithDuration:0.2
animations:^{
// do something
}
completion:^(BOOL finished) {
// do something else
}];
Work fine. Has this happened to anybody else? Not sure what could be causing it, it only happens on this one app, never happened on any other app and it only happens sometimes. Any help appreciated.
Edit:
Just want to clarify.
Animations that i create with 'animateWithDuration' work fine.
Sometimes animations from cocoa don't play for the entire time the app is running.
Try to set the UIView animation parameters before you push your viewcontroller.
Here's an example:
[UIView beginAnimation:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:viewController1.view cache:NO];
[viewController0 pushViewController:viewController1 animated:YES];
[UIView commitAnimations];
Maybe it's because of the boolean u used. My animation is quite the same but it's working fine:
[UIView animateWithDuration:4.0 animations:^(void) {
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
pfeil.alpha = 1.00;
}];
thats my code...any questions?
Maybe you have a lot of data to load in your VC? if you load your data in main thread it stops all user interactions and UI responses for a while.

UIView animation is leaking

In my viewcontroller i am using animation for changing the frame of UIButton and UIView, going from portrait to landscape user can see views growing but problem is animation is leaking everywhere and showing everything coming from different sides.
Here is the code
[UIView beginAnimations:Nil context:Nil];
[UIView setanimationDuration:1];
[view1 setFrame:CGRectMake(100,100,200,300)];
[UIView commitAnimations];
Thanks
Please elaborate more on what "leaking everywhere" means, and does it make a difference if you use block animation:
[UIView animateWithDuration:1.0 delay:0.0 options:nil animations:^{
[view1 setFrame:CGRectMake(100,100,200,300)];
}completion:^(BOOL done){
if (done) {
NSLog(#"animation complete");
}
}];
According to Apple's documentation:
In iOS 4 and later, use the block-based animation methods.
(Recommended)

IPhone SDK - Transition to NavigationController display problem

I am nearly finished with my first IPhone app and everything works fine - except of one very little display bug:
My starscreen is an UIView (Fullscreen) without Navigationbar or Toolbar.
If I tap on a start button, there is an UIViewAnimationTransitionFlipFromRight animation that flips to the main navigation controller:
-(IBAction) switchViewToMainMenu {
[UIView beginAnimations:#"Flip View" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.window cache:YES];
[self.navController viewWillAppear:YES];
[self.startScreenViewController viewWillDisappear:YES];
[self.startScreenViewController.view removeFromSuperview];
[self.window addSubview:navController.view];
[self.startScreenViewController viewDidDisappear:YES];
[self.navController viewDidAppear:YES];
[UIView commitAnimations];
self.startScreenViewController=nil;
[startScreenViewController release];
}
This works fine except of one little problem:
When the navigation controller view appears (flips in), the Navigationbar on top is some pixels too high (the is a white bar where the Navigationbar should be). When the animation finished, the Navigationbar drops down to the right position. This doesn't look very beautiful...
Any ideas how to fix that problem ?
We found a solution using the setAnimationDelay giving some time the tabbar to load and placed in view.
Thought you have to alter the code a little in order to use the setAnimationDelay.
You have to use the setyanimationdelay just before the setanimationtransition and the setanimationtransition just before the commitAnimations. So the code above should end to:
[UIView setAnimationDelay:2]; // 2 seconds delay seems to be working for us
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.window cache:YES];
[UIView commitAnimations];

Modifying an iPhone animation container view before starting animation

I am adding some basic animation to a card game I'm working on. (My first iPhone app.)
I am creating a custom UIView class "AnimationContainer", which flips from image1 to image2, while moving from rect1 to rect2. My ultimate intention is to have up to four of these containers doing their transitions simultaneously.
The problem I'm having is that the animation isn't showing image1... so only the last half of the flip transition appears.
However, if I reset the animation first by touching Reset, then everything works perfectly. In other words, if I press Flip again and again, I only get half the transition... but if I press Reset first, then everything works perfectly for one flip.
So, how can I get the animation to reset itself correctly?
Below is the code, a screenshot, and here's a link to the complete: Project Zip File 700k.
- (void)displayWithImage1 { //RESET button calls this
self.frame = rect1;
[image2 removeFromSuperview];
[self addSubview:image1];
[self setNeedsDisplay]; //no help: doesn't force an update before animation
}
- (void)runTheAnimation { //FLIP button calls this
[self displayWithImage1]; //<---this is what the reset button calls
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:transition forView:self cache:NO];
self.frame = rect2;
[image1 removeFromSuperview];
[self addSubview:image2];
[UIView commitAnimations];
}
Thanks!
You need a drawing loop to pass in order to redraw the view before performing the animation. This code is an example of "draw this, and when the next event loop comes around, do this other thing." It's not uncommon to do this in UI code. Your first work-around is attempting the same thing, but in a much more complicated way.
- (void)_runTheAnimation {
// Moved here from -runTheAnimation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:transition forView:self cache:NO];
self.frame = rect2;
[image1 removeFromSuperview];
[self addSubview:image2];
[UIView commitAnimations];
}
- (void)runTheAnimation { //FLIP button calls this
[self displayWithImage1];
[self performSelector:#selector(_runTheAnimation) withObject:nil afterDelay:0.0];
}

how to implement an iPhone view transition animation with both flipping and scaling?

how can I implement the animation we see in the iPhone Music app's coverflow screen? when you click on a small view, it flips and scales up to another view? how can I do this? I can use core animation to flip and scale a view, but how can I do the transition to another view? thanks
You need an UIView as Container for the two UIViews (frontside/backside) and then remove/add these from/to the container as subviews while doing the animations in between:
UIView *flipContainer;
UIView *frontSide;
UIView *backSide;
//...
-(void)turnUp
{
[backSide removeFromSuperview];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:flipContainer cache:YES];
[UIView setAnimationDuration:1.0];
CGAffineTransform transform = CGAffineTransformMakeScale(1.2, 1.2);
flipContainer.transform = transform;
[UIView commitAnimations];
[flipContainer addSubview:frontSide];
}
-(void)turnDown
{
[frontSide removeFromSuperview];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:flipContainer cache:YES];
[UIView setAnimationDuration:1.0];
CGAffineTransform transform = CGAffineTransformMakeScale(1, 1);
flipContainer.transform = transform;
[UIView commitAnimations];
[flipContainer addSubview:backSide];
}
I'm trying the exact code you are doing - I get a zoom effect but no turn over. The only difference is that right before the turnUp code I add the flipContainer (with back showing) so then it can be flipped over.
// construct animation container
self.flipContainer = [[FlipContainer alloc] init];
[self.flipContainer.view setFrame:CGRectMake(clickedSquareX, clickedSquareY, 200, 200)];
[self.flipContainer.view addSubview:self.backside.view];
// add animation container
[self.myParentView.view addSubview:self.flipContainer.view];
// PROCEED to your turnUp code
The reason I'm doing this is I have a bunch of images in a horizontal UIScrollView and so to 'simulate' a 200x200 image flipping over and zooming to show detail I add my flipContainer with the backside showing the exact image over the exact spot of the pressed image. It should work shouldn't it? A bit confusing to me is the first line of your turnUp code you do:
[backSide removeFromSuperview];
..which would remove the view I just added.
I'm not sure if this is the right spot to put this question in - sorry if it isn't!