How to animate uibuttons in a circular path (Objective C) [closed] - iphone

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
float degrees = -30.0;
float radians = (degrees/180.0) * M_PI;
[UIView animateWithDuration:0.5 animations:^
{
bottomRoundedView.transform = CGAffineTransformMakeRotation(radians);
}
];

Try below code,
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:#"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.repeatCount = INFINITY;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
pathAnimation.duration = 3.0;
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGRect circleContainer = CGRectMake(0, 0, 100, 100);
CGPathAddEllipseInRect(curvedPath, NULL, circleContainer);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);
[self.yourbutton.layer addAnimation:pathAnimation forKey:#"myCircleAnimation"];
circleContainer is the frame for which you need to show the circular animation.
pathAnimation.duration is to adjust the speed of the animation.
if you want to stop the animation then call
[self.yourbutton.layer removeAnimationForKey:#"myCircleAnimation"];

Related

Push animations- I want two different animations for current View and Next View - In iPhone [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am developing a navigation based application. In this application i want some special animations for Push Pop.
I want MoveOut animation for currentViewController and FadeIn animation for nextViewController.
I have used following code. MoveOut animation for the firstViewController works fine. But I cant get FadeIn animation for nextViewController.
- (IBAction)pushClick:(id)sender
{
SecondViewController * sec = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
CATransition *transitionMainView = [CATransition animation];
transitionMainView.duration = 0.4;
transitionMainView.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transitionMainView.type = kCATransitionReveal;
transitionMainView.subtype = kCATransitionFromRight;
transitionMainView.delegate = self;
[self.navigationController.view.layer addAnimation:transitionMainView forKey:nil];
CATransition *transitionSubView = [CATransition animation];
transitionSubView.duration = 0.4;
transitionSubView.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transitionSubView.type = kCATransitionFade;
transitionSubView.subtype = kCATransitionFromLeft;
transitionSubView.delegate = self;
[sec.view.layer addAnimation:transitionSubView forKey:nil];
[self.navigationController pushViewController:sec animated:NO];
}
PLEASE TELL ME SOLUTION FOR POP ALSO.......
Please share your knowledge.....
you should use the following code !
SecondViewController * sec = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
CATransition *transitionMainView = [CATransition animation];
transitionMainView.duration = 0.4;
transitionMainView.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transitionMainView.type = kCATransitionReveal;
transitionMainView.subtype = kCATransitionFromRight;
transitionMainView.delegate = self;
[self.navigationController.view.layer addAnimation:transitionMainView forKey:nil];
[self.navigationController pushViewController:sec animated:NO];
sec.view.alpha = 0;
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:0.75];
sec.view.alpha = 1;
[UIView commitAnimations];

Animate infinite scrolling of an image in a seamless loop not working when back from back ground [duplicate]

This question already has answers here:
Animate infinite scrolling of an image in a seamless loop
(3 answers)
Closed 17 days ago.
I have the following code that run an endless loop of the same image
the problem is when the user minimize the application, and get back to it, the image stop animating and it totally disappear
Here is my code:
-(void)cloudScroll
{
UIImage *cloudsImage = [UIImage imageNamed:#"TitleClouds.png"];
UIColor *cloudPattern = [UIColor colorWithPatternImage:cloudsImage];
CALayer *cloud = [CALayer layer];
cloud.backgroundColor = cloudPattern.CGColor;
cloud.transform = CATransform3DMakeScale(1, -1, 1);
cloud.anchorPoint = CGPointMake(0, 1);
CGSize viewSize = self.cloudsImageView.bounds.size;
cloud.frame = CGRectMake(0, 0, cloudsImage.size.width + viewSize.width, viewSize.height);
[self.cloudsImageView.layer addSublayer:cloud];
CGPoint startPoint = CGPointZero;
CGPoint endPoint = CGPointMake(-cloudsImage.size.width, 0);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"position"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.fromValue = [NSValue valueWithCGPoint:startPoint];
animation.toValue = [NSValue valueWithCGPoint:endPoint];
animation.repeatCount = HUGE_VALF;
animation.duration = 3.0;
[cloud addAnimation:animation forKey:#"position"];
}
Look at UIApplicationDelegate Protocol Reference. In the discussion part of method called applicationDidEnterBackground: you can find answer on your question.
you can try re-firing your animation upon re-opening of the application

crossfade animation between two UIImages in objective-c doesn't fade out the first UIImage

I want to crossfade between two different UIImages but for a reason i cannot figure out my first UIImage stays when the second one fades in.
Here is the sourcecode of my animation (it does a lot more than just crossfading, but the crossfading is my only problem right now).
I need all of the three animations listed below to be executed at the same time.
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath,NULL,startPoint.x, startPoint.y);
CGPathAddLineToPoint(thePath, NULL, endPoint.x, endPoint.y);
CAKeyframeAnimation *positionAnimation =[CAKeyframeAnimation animationWithKeyPath:#"position"];
positionAnimation.path=thePath;
positionAnimation.duration=ti_duration;
positionAnimation.repeatCount=0;
positionAnimation.delegate = self;
positionAnimation.autoreverses=NO;
positionAnimation.fillMode=kCAFillModeForwards;
positionAnimation.removedOnCompletion = NO;
[self.layer addAnimation:positionAnimation forKey:s_direction];
CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:#"contents"];
crossFade.duration = ti_duration;
crossFade.fromValue = (id)img_startImage.CGImage;
crossFade.toValue = (id)img_transferImage.CGImage;
[self.iv_image.layer addAnimation:crossFade forKey:#"animateContentsToTransferState"];
[self.iv_image setImage:img_transferImage];
CAAnimationGroup *theGroup = [CAAnimationGroup animation];
theGroup.duration = ti_duration;
theGroup.repeatCount = 0;
theGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
theGroup.animations = [NSArray arrayWithObjects:/*positionAnimation,*/ crossFade, nil]; // you can add more
[self.layer addAnimation:theGroup forKey:#"move"];
[UIView beginAnimations:#"changeSize" context:nil];
[UIView setAnimationDuration:duration];
self.bounds = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.transferSize.width, self.transferSize.height);
[UIView commitAnimations];
The animation method containing this sourcecode is in a subclass of UIView. This subclass contains several UIImages and one UIImageView where the image to be displayed is contained in.
Have i forgotten some essential thing or why is my first image not fading away?
Can it be because it is animated from some other animation at the same time?
I hope someone can help me with this.
Greets
Maverick
Think of CAAnimations as operations applied to the CALayer. The animations current state do not change the layers original contents.
When the original state seems to snap back at the end of the animation it is actually just the animations operation being removed, and the real layers state is being revealed again.
What you need to do is to register a delegate for your animation, and change the actual self.layer.contents when the animation ends.
First:
crossFade.delegate = self;
Then implement:
- (void)animationDidStop:(CABasicAnimation *)animation finished:(BOOL)flag {
self.layer.contents = animation.toValue;
}
Try this code...It worked for me.
-(void)crossFadeImage{
CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:#"contents"];
crossFade.duration = 2.0;
crossFade.fromValue = img1.CGImage;
crossFade.toValue = img2.CGImage;
[self.background.layer addAnimation:crossFade forKey:#"animateContents"];
self.background.image = img2;
}

Xcode, iphone - Make image animation move in specific direction [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm creating an animated ball which should move across the screen. I want to make it move towards the center of the screen as if it is attracted by the center. How can I do this?
You can try this code
[UIView beginAnimations:nil context:NULL]; //starting Animation
[UIView setAnimationDuration:1.0];
[UIView setAnimationRepeatCount:10];
[UIView setAnimationRrepeatAutoreverses:YES];
CGPoint position = 200.0f;
position.y = 200.0f;
position.x = 150.0f;
img.center = position;
[UIView commitAnimations];
If it is cocos2d,You can use Move method,
id move = [CCMoveTo actionWithDuration:3 position:ccp(160,240);
[sprite runAction:move];
image.center = CGPointMake(image.center.x + 10, image.center.y);

UIView animation along a round path?

I need to make my little guy (in a UIIamgeView) jump forward and it has to look natural. I want to know is there a way to do it with CoreAnimation (beginAnimation/commitAnimation)?
I could do it by setting a point in between in the air but the movement looks not natural :P
Reading Brad Larson's post, I ended up with a nice function to make my image follow a circle.
You need to import QuartzCore framework: #import
Here is the code:
// Set up path movement
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:#"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.repeatCount = INFINITY;
//pathAnimation.rotationMode = #"auto";
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
pathAnimation.duration = 5.0;
// Create a circle path
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGRect circleContainer = CGRectMake(0, 0, 400, 400); // create a circle from this square, it could be the frame of an UIView
CGPathAddEllipseInRect(curvedPath, NULL, circleContainer);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);
[self.imageView.layer addAnimation:pathAnimation forKey:#"myCircleAnimation"];
Create a CAKeyframeAnimation and assign a CGPath to its path property.
To follow up on Ole's answer, my answer to this question provides code to perform such a curved animation using a CAKeyframeAnimation.