Ios 动画按钮两个标签文本更改
这里的问题是,当我点击按钮时,两个标签文本将发生更改,但我无法在此处显示动画功能“我的代码”Ios 动画按钮两个标签文本更改,ios,objective-c,animation,Ios,Objective C,Animation,这里的问题是,当我点击按钮时,两个标签文本将发生更改,但我无法在此处显示动画功能“我的代码” CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; rotate.byValue = @(M_PI*1); // Change to - angle for counter clockwise rotation rotate.duration = 0.4
CABasicAnimation *rotate =
[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotate.byValue = @(M_PI*1); // Change to - angle for counter clockwise rotation
rotate.duration = 0.4;
[_button.layer addAnimation:rotate
forKey:@"myRotationAnimation"];
CATransition *animation = [CATransition animation];
animation.duration = 1.0;
animation.type = kCATransitionFromBottom;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[_name1.layer addAnimation:animation forKey:@"changeTextTransition"];
[_name2.layer addAnimation:animation forKey:@"changeTextTransition"];
// Change the text
_from.text = @"new 222text";
_to.text = @"new text";
但我想要这样的改变
当我点击该箭头按钮时,“从”和“到”地址将出现上下变化动画。请您帮助我,我正在尝试,但我无法像那样理解,谢谢您。请尝试以下代码为您的标签设置动画:
- (CAAnimation*)moveup;
{
CABasicAnimation *animation = [CABasicAnimation animation];
animation.keyPath = @"position.y";
animation.fromValue = @-500;
animation.toValue = @10;
animation.duration = 0.25;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[label1.layer addAnimation:animation forKey:@"basic"];
[label2.layer addAnimation:animation forKey:@"basic"];
label1.layer.position = CGPointMake(0,20);
label2.layer.position = CGPointMake(0,20);
return animation;
}
并根据需要添加尺寸参数。
希望这会很好
您可以通过以下代码进行旋转:
-(CAAnimation*)rotate
{
CGRect boundingRect = CGRectMake(350, -500, -5,-5);
CAKeyframeAnimation *orbit = [CAKeyframeAnimation animation];
orbit.keyPath = @"position";
orbit.path = CFAutorelease(CGPathCreateWithEllipseInRect(boundingRect, NULL));
orbit.duration =0.5;
orbit.additive = YES;
orbit.repeatCount = HUGE_VALF;
orbit.calculationMode = kCAAnimationPaced;
orbit.rotationMode = kCAAnimationRotateAuto;
[btnScan.layer addAnimation:orbit forKey:@"orbit"];
return orbit;
}
我找到了一种在按钮操作时更改标签文本的方法
bool isShown = false;
在按钮操作中:
- (IBAction)textChange:(id)sender {
if (!isShown) {
from.frame = CGRectMake(31, 220, 217 , 38);
to.frame = CGRectMake(31, 275, 217 , 38);
[UIView animateWithDuration:0.25 animations:^{
from.frame = CGRectMake(31, 275, 217, 38);
to.frame = CGRectMake(31, 220, 217 , 38);
}];
isShown = true;
} else {
[UIView animateWithDuration:0.25 animations:^{
from.frame = CGRectMake(31, 220, 217, 38);
to.frame = CGRectMake(31, 275, 217, 38);
}];
isShown = false;
}
}
谢谢。请更改x和y的位置。