ios - CGAffineTransformIdentity 在多次转换后不重置 UIImageView?

标签 ios objective-c core-graphics cgaffinetransform

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

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

当我选择段以旋转 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;

最佳答案

试试这个

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

关于ios - CGAffineTransformIdentity 在多次转换后不重置 UIImageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6847843/

相关文章:

ios - 方向更改时 UINavigationController 工具栏高度

ios - 渐变保持快速在 Collection View 中的单元格之间切换

objective-c - 颜色菜单选择器

objective-c - 我如何将 Microsoft 的 Active Directory 集成到我的 iPhone 应用程序中以在登录时对用户进行身份验证

ios - 如何使用iOS SDK获取Facebook页面封面照片

ios - 为什么当线本身加倍时连接不四舍五入?

iphone - iPhone 上的 CoreGraphics。加载带有预乘 Alpha 的 PNG 文件的正确方法是什么?

ios - 将 Storyboard中的 View 定位在屏幕尺寸的 1/3 处

ios - iTunnesConnect 中的应用名称

ios - 从缓冲区创建的 NSData 创建 UIImage 返回 nil?