transition between 2 UIImages - iphone

I use the code below to transition between two UIImageViews.
-(void)performTransitionNew: (NSInteger)type subType:(NSInteger)subType
fromImageView:(UIImageView *)fromImageView
toImageView:(UIImageView *)toImageView duration:(NSInteger)duration;
{
CATransition *transition = [CATransition animation];
transition.duration = duration;//0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
NSString *types[4] = {kCATransitionMoveIn, kCATransitionPush, kCATransitionReveal, kCATransitionFade};
NSString *subtypes[4] = { kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom};
transition.type = types[type];
transition.subtype = subtypes[subType];
transitioning = YES;
transition.delegate = self;
[self.aUIView.layer addAnimation:transition forKey:nil];
fromImageView.hidden = YES;
toImageView.hidden = NO;
UIImageView *tmp = toImageView;
toImageView = fromImageView;
toImageView = tmp;
}
Both of them are on an UIView 'aUIView'.
I want the result to be like this:
but it displays like this:
It looks like toImageView comes from outside of aUIView.
Any comment is welcome.

The Problem is, that the UIView is on top of the other View (were the slider is) You could change the order of these views. If a UIView is in front of another, the Subviews are also, no matter if they are in the bounds of the parent view or not.

Related

Stopping CATransition animation

I'm using this code to make ripple animation for my view
transition = [CATransition animation];
transition.delegate = self;
transition.duration = 3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
NSString *types[4] = {#"cube", #"rippleEffect", #"cube", #"alignedCube"};
NSString *subtypes[4] = {kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromRight};
transition.type = types[1];
transition.subtype = subtypes[1];
Now I want to stop the animation by means of tap and after that I want to start from the view where I stopped....
I tried for
[view.layer removeAllAnimations];
But I found the following thing doesn't work ..Any Suggestions???
Set the speed of your animation to 0 to pause it and to 1 to resume it again.
Take a look at https://developer.apple.com/library/ios/#qa/qa2009/qa1673.html
You can fetch the current animation state from the CALayer.
#import <QuartzCore/QuartzCore.h>
myView.layer.modelLayer.frame = myView.layer.presentationLayer.frame;

UIView animated swap views (slide down)

This is what i have so far. What I am trying to do is make the starting view (startUpView) to switch to the other view (creatNewGameViewController) by sliding down the screen with the new view. All it does now is switch views normally, but i really want that sliding effect. If anyone can spot the error in my code it would be much appreciated. Thanks
#import "CreateNewGameViewController.h"
#synthesize createNewGameViewController;
UIButton *mainCreateGame = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[mainCreateGame addTarget:self
action:#selector(goToCreateGameViewController)
forControlEvents:UIControlEventTouchUpInside];
[mainScroll addSubview:mainCreateGame];
mainCreateGame.frame = CGRectMake(65, 10, 190, 60);
-(void)goToCreateGameViewController{
CreateNewGameViewController *newGame = [[CreateNewGameViewController alloc]initWithNibName:#"CreateNewGameViewController" bundle:nil];
self.createNewGameViewController = newGame;
CATransition *transition = [CATransition animation];
transition.duration = 2;
transition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type =kCATransitionMoveIn;
CATransition *transition1 = [CATransition animation];
transition1.duration = 2;
transition1.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition1.type =kCATransitionMoveIn;
transition1.subtype =kCATransitionFromTop;
transition1.delegate = self;
[createNewGameViewController.view.layer addAnimation:transition1 forKey:nil];
transition1.subtype =kCATransitionFromTop;
transition1.delegate = self;
[self presentModalViewController:newGame animated:NO];
[self.view insertSubview:newGame.view atIndex:0];
[createNewGameViewController.view.layer addAnimation:transition1 forKey:nil];
[newGame release];
UIView has a class method called transition from view to view animated, check if that helps and tell me how it was :)
UiView
one piece of advice, you should really be using a navigation controller, a storyboard or something like it to do that kind of view transitions because is the proper way to do.

switch two view controller's view in a cube animation

the code below implement the switch between two view in a cube animation .
UIViewController* viewCtrl = [[UIViewController alloc] init:book];
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = #"cube";
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
self.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:viewCtrl animated:YES];
[viewCtrl release];
but, if the view don't belong to self.navigationController, how to do switch in cube animation between two view controller, and then how to scale the current view controller's view in the same time? thanks very much
This worked for me:
-(IBAction)animate:(id)sender {
NSLog(#"animate");
CATransition *transition = [CATransition animation];
transition.delegate = self;
transition.duration = 0.8;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
NSString *types[4] = {#"cube", #"rippleEffect", #"cube", #"alignedCube"};
NSString *subtypes[4] = {kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromRight};
transition.type = types[0];
transition.subtype = subtypes[1];
[self.view.layer addAnimation:transition forKey:nil];
SecondView *_secondViewController = [[SecondView alloc]initWithNibName:#"secondView" bundle:nil];
self.secondViewController = _secondViewController;
_secondViewController = nil;
[[[self view] layer] addAnimation: transition forKey: nil];
[[self view] addSubview: [self.secondViewController view]];
}
-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag{
[self.view release];
}

Custom UIViewAnimationTransition on iPad

I'm wondering if there is any chance to create a custom transition animation between Views, as a "cube":
http://www.pendrivelinux.com/wp-content/uploads/pdl-cubed.jpg
I've took a look for some example, without any success, do you know some, is even possible?
Thanks
UIViewController* viewCtrl = [[UIViewController alloc] init];
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = #"cube"; //Note: undocumented API, will probably cause App Store rejection
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
self.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:viewCtrl animated:YES];
[viewCtrl release];
It should be possible. You will need to have 2 views and a bit of Core Animation 3D transforms.

memory leak when using transition

i get a memory leak and crash when using this transition more then 7-8 times:
-(IBAction)pan1:(id)sender{
CATransition *transition = [CATransition animation];
transition.duration = 0.50;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
NSString *types[4] = {kCATransitionFade};
int rnd = random() % 4;
transition.type = types[rnd];
transitioning = YES;
transition.delegate = self;
UIImage *image4 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"pan_01_cross_0.png" ofType:nil]];
pan_cross_0 = [[UIImageView alloc] initWithImage:image4];
[panView.layer addAnimation:transition forKey:nil];
[panView addSubview:pan_cross_0];
}
At least 1 memory leak I can see with pan_cross_0 if you run the pan method multiple times.
pan_cross_0 = [[UIImageView alloc] initWithImage:image4];
You alloc new image view into pan_cross_0 but not releasing it from the last time. I am not sure what cause crashes. I need more details at least