ios – CGAffineTransformIdentity在多次转换后没有重置UIImageView?

我在顶部创建了一个带有分段控件的简单应用程序.当我单击控件的两个部分之一时,UI ImageView开始旋转.我有一个重置按钮,将其转换为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;

解决方法

试试这个
[UIView animateWithDuration:0.2 animations:^() {

    self.imageView.transform = CGAffineTransformIdentity;



}];

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...