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.
Related
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)];
}];
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)
Really weird issue, i've got a view (view 2) that i'm popping to bring up my main view (view 1) which has an animated background. Once i pop from view 2, view 1 loses those animations... the weird thing is that moving the iOS status bar in the slightest will restart them!
Any ideas?
This is the code that i'm using to pop the view. If I pop the view without animations, it works fine.
-(IBAction)popOnSwipe {
[UIView beginAnimations:#"" context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationCurve:UIViewAnimationTransitionCurlDown];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[navController popViewControllerAnimated:NO];
[UIView commitAnimations];
One more thing; the animation starts back up on the simulator, but not on the iTouch i'm testing it on. Any insight would be greatly appreciated,
thanks!
Add your animations for view1 in DidStopSelector method like,
-(IBAction)popOnSwipe
{
[UIView beginAnimations:#"" context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationCurve:UIViewAnimationTransitionCurlDown];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[UIView setAnimationDidStopSelector:#selector(view1_animation)];//add this line
[navController popViewControllerAnimated:NO];
[UIView commitAnimations];
}
-(void)view1_animation
{
//do animations for view1
}
The device I was using was faulty, the method works fine on my other devices. Thanks for the help.
I have a working view animation, that curls up a container view, while the containerview.subviews changes. (before the animation a UITableView will be shown, after it is a custom view, name keypadView)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:containerView
cache:YES];
[secondView removeFromSuperview];
[containerView addSubview:keypadView];
[UIView commitAnimations];
Now I want to rewrite this code for the iOS4 block-based api, as I want to use the completion block. I wrote this:
[UIView transitionWithView:containerView
duration:.75
options:UIViewAnimationTransitionCurlUp
animations:^{
NSLog(#"Hey Ho");
[secondView removeFromSuperview];
[containerView addSubview:keypadView];
}
completion:NULL];
The views switch — but not animated.
what is wrong with my code?
Edit
completion: ^(BOOL completed){
NSLog(#"completed %d", completed);
}
doesn't help, as NULL is an accepted value, according to the docs
do:
options:UIViewAnimationOptionTransitionCurlUp
instead of:
options:UIViewAnimationTransitionCurlUp
That is why your code works now :).
The sample in the UIView class reference may be wrong - or maybe there's a bug with adding and removing views in the animations block object, but the only way I've been able to get it to work is as follows:
[secondView removeFromSuperview];
[containerView addSubview:keypadView];
[UIView transitionWithView:containerView
duration:.75
options:UIViewAnimationOptionTransitionCurlUp
animations:^{}
completion:^(BOOL finished) {
NSLog(#"finished %d", finished);
}];
Did you leave [UIView beginAnimations:nil context:nil]; above your new block?
Is the completion block always NULL? Try putting an NSLog statement in there or something. I don't know if NULL blocks would mess it up.
all coder , I see the foldout animation view in the original iPhone google map app, I want the same effect in my view , but I have not find solution ...
how to do the same animation via iPhone sdk ? any tip will be much appreciated...
thanks...
iRobin
I believe that what you're looking for is UIViewAnimationTransitionCurlUp and UIViewAnimationTransitionCurlDown, two transition effects that can be applied when switching views. To produce the effect, you could use code like the following:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:CURLANIMATIONDURATIONFORSWITCHINGVIEWS];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[newlyVisibleController viewWillAppear:YES];
[previouslyVisibleController viewWillDisappear:YES];
[previouslyVisibleController.view removeFromSuperview];
[self.view addSubview:newlyVisibleController.view];
[previouslyVisibleController viewDidDisappear:YES];
[newlyVisibleController viewDidAppear:YES];
[UIView commitAnimations];