UIView setAnimationTransition is not working? - iphone

i have added one view in UIwindow as
[window addSubview:parVC.view];
i toggle the parVC.view through the following , but it is not working
- (IBAction)flipToback:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:parVC.view
cache:YES];
[parVC.view addSubview:imgController.view];
[UIView commitAnimations];
}
I have set correctly imgController.view in IB in app delegate. I want to avoid window in forView. If i give window instead of forView:parVC.view , it works fine....

That sounds like the correct behavior to me. setAnimationTransition:forView:cache: operates on the container view, not the one you're adding.

Related

popviewcontroller from view 2 causes view 1 to stop animating its background

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.

different type of animation in iPhone

I am new to iPhone developer,
I want to implement different Animations on button click, i have 5 Button in my home page
on each click of button, i want to navigate to a new page with different Animation so i want to know what are the different animation available in iPhone.
so far i have found only 2 animation,
(1)
[UIView beginAnimations:#"yourAnim" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:yourView cache:cacheFlag];
...
[UIView commitAnimations];
(2)
[UIView beginAnimations:#"yourAnim" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:yourView cache:cacheFlag];
...
[UIView commitAnimations];
Thanks In Advance !
This link provides the UIView Animation. Go through it.
http://www.raywenderlich.com/5478/uiview-animation-tutorial-practical-recipes
These are 5 different Animation Transition:
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
Look at CATransition class too
https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CATransition_class/Introduction/Introduction.html
I think bellow method from you can test different type of Transition Animation....
- (void) pushController: (UIViewController*) controller
withTransition: (UIViewAnimationTransition) transition
{
[UIView beginAnimations:nil context:NULL];
[self pushViewController:controller animated:NO];
[UIView setAnimationDuration:.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
You Can Get Idea From this May Be.....

UIView shows the subview view sometimes?

I am developing iOS game and need custom animation so I am using this method
CGRect basketTopFrame = mainScreenView.frame;
basketTopFrame.origin.x = 320;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
mainScreenView.frame = basketTopFrame;
[UIView commitAnimations];
in the .h file I have declared mainScreen like this
IBOutlet UIView *mainScreenView;
So in the IB I have put UIView in the view in the interface and hooked it up with mainScreenView
So in the mainViewScreen the view sometimes shows up sometimes doesn't (works on the 2nd try) however when I remove the animation code it works perfectly fine..I don't know what is happening any help would be appreciated thanks
edit
this is how I added the view
MainScreen *mainScreen = [[MainScreen alloc]initWithNibName:#"MainScreen" bundle:nil];
[mainScreenView addSubview:mainScreen.view];
I tried it in a sandbox project, and this worked for me:
- (IBAction)buttonTouched:(id)sender {
myView.transform = CGAffineTransformMakeTranslation(-320, 0);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
myView.transform = CGAffineTransformMakeTranslation(0,0);
[UIView commitAnimations];
}
Looks like you are trying to move something off screen. An easier way is to do this
[UIView beginAnimations:#"UIBase Hide" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
mainScreenView.transform = CGAffineTransformMakeTranslation(320,0); //slide view to the right.
[UIView commitAnimations];
note: using 320 on the Translation wont move the view to the 320th pixel of the screen rather it moves your view 320px to the right. So if your mainScreenView is at origin.x = 100. After this translation it is now at 420.
To move it back do
self.transform = CGAffineTransformIdentity;

how to make the animation between one view to another view in uitabbarcontroller

I want the animation between the two viewcontrollers in uitabbarcontroller.
I am having the two tabbar. The first one open by default when run the app.I want the animation,while i go to the second tabbar.How can i do this.
Thanks
In the View Will appear of your firstViewController you should have something like
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView commitAnimations];
}
Then in the secondviewcontroller have the same thing but
UIViewAnimatinTransitionFlipFromleft
However let me know how this goes, because for some reason in the app I was making I had a little trouble on the view first transition then it would work fine after that. If you suffer from the same problem maybe we can work together for a solution.

adding a category for UIView animations

I would like to have a category for UIViewController containing few simple methods to move the view controller's view around, fading it etc...
For example the method below fades in/out a the VC's view.
I'm not using instance variables and the onTransitionIn: method is called, the problem is the view doesn't fade in/out.
Can someone tell me what I'm doing wrong?
Thank you!
EXAMPLE:
#implementation UIViewController (UIViewControllerAdditions)
- (void)onTransitionIn:(BOOL)isIn {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:ANIM_DUR];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
int newAlpha = 1;
if (!isIn) {
newAlpha = 0;
[UIView setAnimationDidStopSelector:#selector(hideAnimationDidStop)];
}
// set the new alpha
self.view.alpha = newAlpha;
[UIView commitAnimations];
}
Try adding this:
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView: self.view cache:YES];
after the line:
[UIView setAnimationDelegate:self];
Also take a look at these:
iPhone UIView Animation Best Practice
How to animate View swap on simple View iPhone App?