如何停止和扭转UIView的动画
2016-03-01 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517198
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
DM做的基于块的动画,如果你想停止动画并启动一个新的活力,一种能将UIViewAnimationOptionBeginFromCurrentState选项:[UIView animateWithDuration:3.0
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction
animations:^{
// specify the new `frame`, `transform`, etc. here
}
completion:NULL];
您可以通过新建停止当前动画师和动画启动在哪里当前的不放过实现这一目标。为此 CodeGo.net,您可以与quartz2D: 添加QuartzCore。你的项目,如果你还没有。 导入所需的头,如果你已经有了不:#import <QuartzCore/QuartzCore.h>
让你的脚停止现有的动画:[self.subview.layer removeAllAnimations];
获取参考电流表示层(即视图的状态,因为它恰恰是在这CALayer *currentLayer = self.subview.layer.presentationLayer;
重置transform(或者frame或无论)根据在当前值presentationLayer:self.subview.layer.transform = currentLayer.transform;
现在,领导者从该transform(或者frame或其他)为新值:[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
self.subview.layer.transform = newTransform;
}
completion:NULL];
把所有的一起,这里就是我的切换尺度变换的2.0倍确定并背例程:- (IBAction)didTouchUpInsideAnimateButton:(id)sender
{
CALayer *currentLayer = self.subview.layer.presentationLayer;
[self.subview.layer removeAllAnimations];
self.subview.layer.transform = currentLayer.transform;
CATransform3D newTransform;
self.large = !self.large;
if (self.large)
newTransform = CATransform3DMakeScale(2.0, 2.0, 1.0);
else
newTransform = CATransform3DIdentity;
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
self.subview.layer.transform = newTransform;
}
completion:NULL];
}
或者,如果你想切换frame尺寸从100×100到200×200和背部:- (IBAction)didTouchUpInsideAnimateButton:(id)sender
{
CALayer *currentLayer = self.subview.layer.presentationLayer;
[self.subview.layer removeAllAnimations];
CGRect newFrame = currentLayer.frame;
self.subview.frame = currentLayer.frame;
self.large = !self.large;
if (self.large)
newFrame.size = CGSizeMake(200.0, 200.0);
else
newFrame.size = CGSizeMake(100.0, 100.0);
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
self.subview.frame = newFrame;
}
completion:NULL];
}
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction
animations:^{
// specify the new `frame`, `transform`, etc. here
}
completion:NULL];
您可以通过新建停止当前动画师和动画启动在哪里当前的不放过实现这一目标。为此 CodeGo.net,您可以与quartz2D: 添加QuartzCore。你的项目,如果你还没有。 导入所需的头,如果你已经有了不:#import <QuartzCore/QuartzCore.h>
让你的脚停止现有的动画:[self.subview.layer removeAllAnimations];
获取参考电流表示层(即视图的状态,因为它恰恰是在这CALayer *currentLayer = self.subview.layer.presentationLayer;
重置transform(或者frame或无论)根据在当前值presentationLayer:self.subview.layer.transform = currentLayer.transform;
现在,领导者从该transform(或者frame或其他)为新值:[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
self.subview.layer.transform = newTransform;
}
completion:NULL];
把所有的一起,这里就是我的切换尺度变换的2.0倍确定并背例程:- (IBAction)didTouchUpInsideAnimateButton:(id)sender
{
CALayer *currentLayer = self.subview.layer.presentationLayer;
[self.subview.layer removeAllAnimations];
self.subview.layer.transform = currentLayer.transform;
CATransform3D newTransform;
self.large = !self.large;
if (self.large)
newTransform = CATransform3DMakeScale(2.0, 2.0, 1.0);
else
newTransform = CATransform3DIdentity;
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
self.subview.layer.transform = newTransform;
}
completion:NULL];
}
或者,如果你想切换frame尺寸从100×100到200×200和背部:- (IBAction)didTouchUpInsideAnimateButton:(id)sender
{
CALayer *currentLayer = self.subview.layer.presentationLayer;
[self.subview.layer removeAllAnimations];
CGRect newFrame = currentLayer.frame;
self.subview.frame = currentLayer.frame;
self.large = !self.large;
if (self.large)
newFrame.size = CGSizeMake(200.0, 200.0);
else
newFrame.size = CGSizeMake(100.0, 100.0);
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
self.subview.frame = newFrame;
}
completion:NULL];
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询