如何停止和扭转UIView的动画
本文转载至 http://codego.net/576089/
我有它收缩时碰到切换按钮UIView的动画跳和它扩展恢复到原来的大小当再次接触到按钮。密封式前大灯一切都工作得很好。问题是,动画师注意到-例如3秒钟。在此期间,我还是希望能够进行交互的接口。当再次接触到跳跃键,而动画仍在进行中的动画应该就停在哪里是和反向。 在苹果Q&正如我已经找到了方法,所有的动画 但我没有看到从这里扭转动画(并省略原动画的其余部分)的方式。我该怎么办呢?
- (IBAction)toggleMeter:(id)sender {
if (self.myView.hidden) {
self.myView.hidden = NO;
[UIView animateWithDuration:3 animations:^{
self.myView.transform = expandMatrix;
} completion:nil];
} else {
[UIView animateWithDuration:3 animations:^{
self.myView.transform = shrinkMatrix;
} completion:^(BOOL finished) {
self.myView.hidden = YES;
}];
}
}
+
本文地址 :CodeGo.net/576089/
-------------------------------------------------------------------------------------------------------------------------
1. 除了以下(在此我们抓住当前状态从表现层,停止动画,重新保存从表现层的当前状态,并启动新的动画),有很多简单的解决方案。 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];
}
顺便说一句,虽然一般并不重要的真快动画,缓慢动画像你这样的,你可能需要设置动画的持续时间是扭转多远你在你目前的动画已经提前拒绝(例如,如果你是0.5秒到3.0秒的动画,当反向,不可思议不要想拿3.0秒扭转这一方面做了跳跃灯塔动画师的小部分,而仅仅0.5秒)。这可能看起来像:
- (IBAction)didTouchUpInsideAnimateButton:(id)sender
{
CFTimeInterval duration = kAnimationDuration; // default the duration to some constant
CFTimeInterval currentMediaTime = CACurrentMediaTime(); // get the current media time
static CFTimeInterval lastAnimationStart = 0.0; // media time of last animation (zero the first time)
// if we previously animated, then calculate how far along in the previous animation we were
// and we'll use that for the duration of the reversing animation; if larger than
// kAnimationDuration that means the prior animation was done, so we'll just use
// kAnimationDuration for the length of this animation
if (lastAnimationStart)
duration = MIN(kAnimationDuration, (currentMediaTime - lastAnimationStart));
// save our media time for future reference (i.e. future invocations of this routine)
lastAnimationStart = currentMediaTime;
// if you want the animations to stay relative the same speed if reversing an ongoing
// reversal, you can backdate the lastAnimationStart to what the lastAnimationStart
// would have been if it was a full animation; if you don't do this, if you repeatedly
// reverse a reversal that is still in progress, they'll incrementally speed up.
if (duration < kAnimationDuration)
lastAnimationStart -= (kAnimationDuration - duration);
// grab the state of the layer as it is right now
CALayer *currentLayer = self.subview.layer.presentationLayer;
// cancel any animations in progress
[self.subview.layer removeAllAnimations];
// set the transform to be as it is now, possibly in the middle of an animation
self.subview.layer.transform = currentLayer.transform;
// toggle our flag as to whether we're looking at large view or not
self.large = !self.large;
// set the transform based upon the state of the `large` boolean
CATransform3D newTransform;
if (self.large)
newTransform = CATransform3DMakeScale(2.0, 2.0, 1.0);
else
newTransform = CATransform3DIdentity;
// now animate to our new setting
[UIView animateWithDuration:duration
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
self.subview.layer.transform = newTransform;
}
completion:NULL];
}
+
2. 有一招做到这一点,但它是必要写的收缩(和另一个类似的一个利差):
- (void) shrink {
[UIView animateWithDuration:0.3
animations:^{
self.myView.transform = shrinkALittleBitMatrix;
}
completion:^(BOOL finished){
if (continueShrinking && size>0) {
size=size-1;
[self shrink];
}
}];
}
0.3秒每一个在其中收缩整个动画的十分之一现在跳,关键是要缩小动画动画的3秒打入10(或10多,当然):shrinkALittleBitMatrix。在每个动画完成后调用只当布尔伊瓦continueShrinking当int是真实的Ivarsize为正(在全尺寸的视图。将大小=10,以最小的尺寸的视图。将大小=0)。当您按下按钮更改伊瓦continueShrinking为false,然后调用expand。这将停止动画在小于0.3秒。 好了,你必须填写详细资料,但我希望它能帮助。 +
3. 才能评价与互动的用户界面,而动画是一个
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
//Your animation
} completion:^(BOOL finished) {
}];
+
本文地址 :CodeGo.net/576089/
如何停止和扭转UIView的动画的更多相关文章
- iOS开发UI篇—核心动画(UIView封装动画)
iOS开发UI篇—核心动画(UIView封装动画) 一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画 ...
- ios uiview封装动画(摘录)
iOS开发UI篇—核心动画(UIView封装动画) 一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画 ...
- IOS UIVIEW layer动画 总结(转)
转发自:http://www.aichengxu.com/article/%CF%B5%CD%B3%D3%C5%BB%AF/16306_12.html IOS UIVIEW layer动画 总结, ...
- 17-UIKit(UIView的动画)
2. UIView的动画 UIView类本身具有动画的功能 2.1 概念 由UI对底层Core Animation框架的封装 可以轻松简单的实现动画效果 2.2 两种使用方式 1> Block ...
- iOS开发——动画编程Swift篇&(一)UIView基本动画
UIView基本动画 // MARK: - UIView动画 ------------------------------------- // MARK: - UIView动画-淡入 @IBActio ...
- 用layer添加UIView的动画
项目有时会遇到用UIView 添加动画的情况,这里我觉得在layer上添加动画比较好,因为可以详细地设定动画属性,方便理解 下面是一个旋转动画: -(void)roundBtnAction:(id)s ...
- IOS开发-UIView之动画效果的实现方法(合集)
http://www.cnblogs.com/GarveyCalvin/p/4193963.html 前言:在开发APP中,我们会经常使用到动画效果.使用动画可以让我们的APP更酷更炫,最重要的是优化 ...
- iOS开发给UIView添加动画Animation
self.testView需要添加动画的view 1.翻转动画 [UIView beginAnimations:@"doflip" context:nil]; [UIView se ...
- UIView封装动画--iOS利用系统提供方法来做转场动画
UIView封装动画--iOS利用系统提供方法来做转场动画 UIViewAnimationOptions option; if (isNext) { option=UIViewAnimationOpt ...
随机推荐
- JQuery日记_5.14 Sizzle选择器(七)
上篇说道,tokenize方法会把selector切割成一个个selector逻辑单元(如div>a是三个逻辑单元 'div','>','a')并为之片段赋予相应类型的过滤函数. for ...
- 小伙子又乱码了吧-Java字符编码原理总结
前提 配合前面阅读的I/O和NIO的资料,现在总结一下关于字符集和乱码问题的原理和解决方案.参考资料: 码表ASCII Unicode GBK UTF-8 字符编码笔记ASCII,Unicode和UT ...
- Python程序员的10个常见错误
关于Python Python是一门解释性的,面向对象的,并具有动态语义的高级编程语言.它高级的内置数据结构,结合其动态类型和动态绑定的特性,使得它在快速应用程序开发(Rapid Applicatio ...
- [Mac A]如何学习Mac编程?
http://ourcoders.com/thread/show/5550/ @tinyfool 看了您在quora上回答的『为什么说程序员是最好的职业』,加上本来就想学编程(但是一直以来因为各种借口 ...
- HDU 4632 Palindrome subsequence(区间dp)
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...
- SQL优化- 数据库SQL优化——使用EXIST代替IN
数据库SQL优化——使用EXIST代替IN 1,查询进行优化,应尽量避免全表扫描 对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引 . 尝试下面的 ...
- 基于环信的仿QQ即时通讯的简单实现
代码地址如下:http://www.demodashi.com/demo/11645.html 我的博客地址 之前一直想实现聊天的功能,但是感觉有点困难,今天看了环信的API,就利用下午的时间动手试了 ...
- HBase总结(十八)Hbase rowkey设计一
hbase所谓的三维有序存储的三维是指:rowkey(行主键),column key(columnFamily+qualifier),timestamp(时间戳)三部分组成的三维有序存储. 1.row ...
- xcode7.1.1不能真机调试ios9.2系统设备的解决方法
转载自:http://www.cocoachina.com/bbs/read.php?tid-331335.html 前些天手机升级到iOS9.2版本号 xcode7.1还能真机測试. 昨晚更新xc ...
- springboot学习(三) springboot文件配置
1.简介 springboot没有了原来自己整合Spring应用时繁多的XML配置内容,替代它的是在pom.xml中引入模块化的Starter POMs,其中各个模块都有自己的默认配置,所以如果不是特 ...