I would like to ask is it possible to translate the UIButton position?
How? Anyone?
You can get the frame of the button using "frame" property. This returns a CGRect object which basically has your buttons x-coord, y-coord, width and height.
Based on where you want to translate your button, calculate the new x-coord and y-coord.
Then do the following:
btnMyButton.frame = CGRectMake(oldx,oldy,width,height);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:btnMyButton];
[UIView setAnimationDuration:0.3];
btnMyButton.frame = CGRectMake(newx, newy, width, height);
[UIView commitAnimations];
Related
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];
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;
Is there a way to animate a change in the font size of some text. I was thinking to call drawRect from a subclass of UIView and draw the text at different sizes.
You can animate the transform on any UIView including labels.
[UIView beginAnimations:nil context:nil];
label.transform = CGAffineTransformMakeScale(1.5,1.5);
[UIView commitAnimations];
That will scale the text up to 150%. It may become blocky if you make it too big.
Have you tried this?
[UIView beginAnimations:nil context:self.view];
[UIView setAnimationDuration:0.5];
label.font = [UIFont font...]; //try setting the font and the size you want
[UIView commitAnimations];
I created a UIImageView that has a custom shadowPath. This view will be moved left and right across the screen, but I need the shadowPath to have a different transformation than the image layer itself. Is this possible? Moving the image itself works, and the shadow moves as well when I do the following:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
im.center = location;
[UIView commitAnimations];
But if I try to add a layer transformation before "commitAnimations", the shadow will simply take on that property right away, for example:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
im.center = location;
im.layer.shadowPath = [self createPerspectiveShadow:im]; //this will not animate
[UIView commitAnimations];
So, my question is, is there a way to recalculate a shadow during the animation?
Thanks
The UIView animations don’t always allow you to animate CALayer attributes; try using a CABasicAnimation instead.
You can pass a CGPathREf to the toValue
theAnimation.toValue = (id)[UIBezierPath bezierPathWithRect:newRect].CGPath;
see this post
i like to animate my image "finga" not centered but from left or right:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationRepeatCount:1];
finga.transform = CGAffineTransformMakeScale(2,1.5);
finga.animationDuration = 2;
[UIView commitAnimations];
If I understand your question, you need to move the finga view off screen left or right (set the frame) prior to doing your animation.