UIView CATransform3DMakeRotation horizontally from left to right - iphone

I am trying to rotate my view horizontally from left to right. So I am using CATransform3DMakeRotation to do rotation.
Here is my code,
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
newView.layer.transform = CATransform3DMakeRotation(M_PI/2,0,1.0,0.0);
[UIView commitAnimations];
This code really works, But it rotates my view half only.. I want to make full rotation.
So i changed the value M_PI/2 into M_PI, like this
CATransform3DMakeRotation(M_PI,0,1.0,0.0);
But for this value, my view is not rotating at all. Please give me some suggestion.

UIImageView *imageView = [[[UIImageView alloc] init] autorelease]; // Don't forget to release this! I added autorelease.
imageView.image = [UIImage imageNamed:#"photo1.png"];
imageView.frame = CGRectMake(0, 0, viewOutlet.frame.size.width, viewOutlet.frame.size.height);
[viewOutlet addSubview:imageView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
viewOutlet.layer.anchorPoint = CGPointMake(0.0f, 0.5f);
viewOutlet.layer.transform =CATransform3DMakeRotation(M_PI,0,1.0,0.0);
[UIView commitAnimations];
** viewOutlet is Your view outlet so don't forget to IBOutlet it.

Related

UIView Animation not working properly in IOS 7

I have a method to animate and reset the view which is given below.
-(void)animateToFocus:(BOOL)animate index:(NSInteger)index {
if (animate) {
[UIView beginAnimations:#"Scroll" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationsEnabled:YES];
self.view.frame = CGRectMake(0, -50*index, self.view.bounds.size.width, self.view.bounds.size.height);
[UIView commitAnimations];
} else {
[UIView beginAnimations:#"Scroll" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationsEnabled:YES];
self.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
[UIView commitAnimations];
}
}
When I pass YES and a tag in this method, it will animate to top and when I pass NO it will reset the view.
It works perfectly in IOS6.When i update to IOS 7, resetting done as:
It will not animate completeley and a black space appear in the bottom. Can u please help me to solve this?
I'm guessing that's a UITableView inside?
If so, you shouldn't be animating it's frame you should use:
– scrollToRowAtIndexPath:atScrollPosition:animated:
or:
– scrollToNearestSelectedRowAtScrollPosition:animated:

View animation frame change

Are emerging in the subview scrolling animation. However actionsheet place when you scroll subview, not again appear in the first place.
if(checkboxState == 0)
{
NSTimeInterval animationDuration = 0.8;
CGRect newFrameSize = CGRectMake(0, 155,320,120);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:animationDuration];
subview.frame = newFrameSize;
[UIView commitAnimations];
}
else if(checkboxState == 1)
{
NSTimeInterval animationDuration = 0.8;
CGRect newFrameSize = CGRectMake(0, 105,320,120);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:animationDuration];
subview.frame = newFrameSize;
[UIView commitAnimations];
}
Pressing the View is a checkbox in the above code is provided to move up and down. However, even though actionsheet slipped up again when the first view is in place.
View is scrolled up, how can we keep it that way, even if opened actionsheet?
Use [UIView setAnimationBeginsFromCurrentState:YES]; after both "beginAnimation".
Then the previous changes will be saved.
I fixed the problem by using the
subview.bounds
Thank you for your helps.

How to make an UIView come top to bottom and vice versa on drag

I am trying to do an animation where a UIView should come from top to bottom(or till mid of screen) when we toch on top of the screen and drag down.
Set your view frame, and then add these code in your button action or else.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:1.0];
[yourView setFrame:CGRectMake(0, 250, 320, 100)];
[UIView commitAnimations];
set positions according to ur need
[UIView beginAnimations:#"DragView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:0.5f];
self.dragView.frame = CGRectMake(newXPose, newYPose,width, height);
[UIView commitAnimations];

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;

Spawning infinite UIImageViews without name collisions

iPad app. OS 4.2.
I have a button that, when pressed, calls this function that creates a UIImageView and animates it (and calls a second animation block). I created another button that calls the same function and passes different locations and different URL to a graphic.
I'm starting to get glitches—the first graphic spawned from the first button has the locations passed from the second button. This is probably due to the fact that I am not dynamically naming the UIImageView and getting collisions from that.
So how do I dynamically create and name any infinite number of UIImageViews? Especially since, to reference the UIImageView in two functions, it needs to be declared outside of the functions.
-(void)makeSoundEffectWordAppear:(NSString *)imageName:(int)startingX:(int)startingY:(int)endingX:(int)endingY{
myImage = [UIImage imageNamed:imageName];
[testWord setImage:myImage];
testWord = [[[UIImageView alloc] initWithFrame:CGRectMake(startingX,startingY,myImage.size.width,myImage.size.height)] autorelease];
[self.view addSubview:testWord];
testWord.alpha=0;
testWord.transform = CGAffineTransformMakeScale(.5, .5);
[UIView beginAnimations:#"moveWord" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(fadeWord:finished:context:)];
//[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationBeginsFromCurrentState:YES];
testWord.transform = CGAffineTransformMakeScale(1, 1);
testWord.center = CGPointMake(endingX,endingY);
testWord.alpha=1;
[UIView commitAnimations];
}
- (void)fadeWord:(NSString *)animationID finished:(BOOL)finished context:(void *)context{
[UIView beginAnimations:#"makeWordFade" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:5];
testWord.alpha=0;
testWord.transform = CGAffineTransformMakeScale(.5, .5);
[UIView setAnimationDuration:1];
[UIView commitAnimations];
}
You have a single pointer to testWord rather than a pointer for each instance. You should be using the context property of animations to pass in the specific UIImageView you want to fade away:
-(void)makeSoundEffectWordAppear:(NSString *)imageName:(int)startingX:(int)startingY:(int)endingX:(int)endingY{
UIImage *myImage = [UIImage imageNamed:imageName];
UIImageView *testWord = [[[UIImageView alloc] initWithImage:myImage] autorelease];
CGRect frame = [testWord frame];
frame.origin.x = startingX;
frame.origin.y = startingY;
[testWord setFrame:frame];
[self.view addSubview:testWord];
testWord.alpha=0;
testWord.transform = CGAffineTransformMakeScale(.5, .5);
[UIView beginAnimations:#"moveWord" context:testWord];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(fadeWord:finished:context:)];
//[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationBeginsFromCurrentState:YES];
testWord.transform = CGAffineTransformMakeScale(1, 1);
testWord.center = CGPointMake(endingX,endingY);
testWord.alpha=1;
[UIView commitAnimations];
}
- (void)fadeWord:(NSString *)animationID finished:(BOOL)finished context:(void *)context{
UIImageView *testWord = (UIImageView *)context;
[UIView beginAnimations:#"makeWordFade" context:context];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:5];
testWord.alpha=0;
testWord.transform = CGAffineTransformMakeScale(.5, .5);
[UIView setAnimationDuration:1];
[UIView commitAnimations];
}