我怎么能中断/停止动画,当我转? [英] how can I interrupt/stop animation when I rotate?

查看:160
本文介绍了我怎么能中断/停止动画,当我转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我用的是动画景观状态,持续时间为5.0S,从状态A至B;在5.0S的中间,我可以从横向旋转iPad上的画像。我希望动画停止,使UI状态C I旋转后。

我不知道我的问题是清楚的。
我该怎么做?

我的动画code:

   - (无效)moveImage:(UIImageView的*)图像持续的时间:(NSTimeInterval)持续时间X:(NSNumber的*)DX Y:(NSNumber的*)DY
{    //设置动画
    [UIView的beginAnimations:无背景:NULL];
    [UIView的setAnimationDuration:时间];
    [UIView的setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView的setAnimationBeginsFromCurrentState:YES];    //变换矩阵
    浮FX = [DX的floatValue]
    浮FY = [DY的floatValue]    CGAffineTransform变换= CGAffineTransformMakeTranslation(FX,FY);
    // CGAffineTransform变换= CGAffineTransformMakeRotation(0.4);
    // CGAffineTransform变换= CGAffineTransformMakeScale(2.0,2.0);    image.transform =变换;    //提交更改
    [UIView的commitAnimations];
}


解决方案

  1. <一个href=\"http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/AnimatingLayers.html\"相对=nofollow>启动和停止明确动画 对启动和停止核心动画节

  2. <一个href=\"http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html\"相对=nofollow> willRotateToInterfaceOrientation:持续时间 通知用户旋转开始时

因此​​,所有需要做的就是从2 1))

For example, I use the animation in landscape status, duration is 5.0s, from status A to B; in the middle of the 5.0s, I may rotate the iPad from landscape to portrait. I want the animation stopped and make the UI status to C after I rotated.

I'm not sure my question is clear. How can I do that?

my animation code:

- (void)moveImage:(UIImageView *)image duration:(NSTimeInterval)duration x:(NSNumber*)dx y:(NSNumber*)dy
{

    // Setup the animation
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationBeginsFromCurrentState:YES];

    // The transform matrix
    float fx = [dx floatValue];
    float fy = [dy floatValue];

    CGAffineTransform transform = CGAffineTransformMakeTranslation(fx, fy);
    //CGAffineTransform transform = CGAffineTransformMakeRotation(0.4);
    //CGAffineTransform transform = CGAffineTransformMakeScale(2.0, 2.0);

    image.transform = transform;

    // Commit the changes
    [UIView commitAnimations];    
}

解决方案

  1. Starting and Stopping Explicit Animations has a section on starting and stopping core animations
  2. willRotateToInterfaceOrientation:duration notifies you when the rotation begins.

So all have to do is 1) from 2)

这篇关于我怎么能中断/停止动画,当我转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆