【问题标题】:CGAffineTransformIdentity not resetting a UIImageView after multiple transforms?CGAffineTransformIdentity 在多次转换后没有重置 UIImageView?
【发布时间】:2011-07-27 16:24:03
【问题描述】:

我创建了一个顶部带有分段控件的简单应用程序。当我单击控件的两个部分之一时, UIImageView 开始旋转。我连接了一个重置​​按钮以将其转换设置为 CGAffineTransformIdentity。

当通过来回切换段来第二次调用执行视图旋转动画的方法时会出现问题。点击重置只会删除最近的动画。我必须再次切换片段才能让动画完全停止并重置。

当我选择要旋转 UIImageView 的段时调用以下代码,并且显然在我在段之间单击时第二次调用。

// Begin the animation block and set its name
[UIView beginAnimations:@"Rotate Animation" context:nil];

// Set the duration of the animation in seconds (floating point value)
[UIView setAnimationDuration:0.5];

// Set the number of times the animation will repeat (NSIntegerMax setting would repeat indefinately) (floating point value)
[UIView setAnimationRepeatCount:NSIntegerMax];

// Set the animation to auto-reverse (complete the animation in one direction and then do it backwards)
[UIView setAnimationRepeatAutoreverses:YES];

// Animation curve dictates the speed over time of an animation (UIViewAnimationCurveEaseIn, UIViewAnimationCurveEaseOut, UIViewAnimationCurveEaseInOut, UIViewAnimationCurveLinear)
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

// Changes the imageViews transform property to rotate the view using CGAffineTransformRotate
// CGAffineTransformRotate(transformToStartFrom, angleToRotateInRadians)
// Starting transform property can be set to CGAffineTransformIdentity to start from views original transform state
// This can also be done using CGAffineTransformMakeRotation(angleInRadians) to start from the IdentityTransform without implicitly stating so
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, degreesToRadians(90));

[UIView commitAnimations];

重置按钮调用此代码-

self.imageView.transform = CGAffineTransformIdentity;

【问题讨论】:

    标签: ios objective-c core-graphics cgaffinetransform


    【解决方案1】:

    试试这个

    [UIView animateWithDuration:0.2 animations:^() {
        self.imageView.transform = CGAffineTransformIdentity;
    }];
    

    【讨论】:

    • 动画持续时间(0.2秒)是否会添加想要的效果?请多解释一下..
    • 你可以设置你想要的值,我只是展示了它有持续时间选项。干杯:)
    • 问题说他已经在设置 ​​CGAffineTransformIdentity 并且它不起作用
    • 你认真读过这个问题吗?为什么这有赞成票?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-13
    • 2013-10-13
    • 2013-07-07
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 2010-11-08
    相关资源
    最近更新 更多