13

我将如何完成此代码我有错误。

-(IBAction)dropDownBtn:(id)sender {

 dropDownBtn.transform = CGAffineTransformMakeRotation(720*M_PI/360);

if ([dropDownBtn.transform CGAffineTransformMakeRotation(720*M_PI/360)) {

    dropDownBtn.transform = CGAffineTransformMakeRotation(520*M_PI/360);
    }
}
4

4 回答 4

30

有一个比较变换的函数:

CGAffineTransformEqualToTransform(transform1, transform2)
于 2013-10-25T07:10:00.417 回答
2

在 Swift 中,您使用等于运算符 (==)

transform1 == transform2
于 2016-10-04T15:45:47.580 回答
1

如果您需要具有给定精度的相等测试(在单元测试中很有用),我使用此功能:

BOOL CGAffineTransformEqualToTransformWithAccuracy (CGAffineTransform firstTransform, CGAffineTransform secondTransform, CGFloat epsilon) {
    return (fabs(firstTransform.a - secondTransform.a) <= epsilon) &&
            (fabs(firstTransform.b - secondTransform.b) <= epsilon) &&
            (fabs(firstTransform.c - secondTransform.c) <= epsilon) &&
            (fabs(firstTransform.d - secondTransform.d) <= epsilon) &&
            (fabs(firstTransform.tx - secondTransform.tx) <= epsilon) &&
            (fabs(firstTransform.ty - secondTransform.ty) <= epsilon);
}
于 2014-10-27T14:41:41.200 回答
0

这是一个扩展:

import CoreGraphics

extension CGAffineTransform: Equatable {}

public func ==(lhs: CGAffineTransform, rhs: CGAffineTransform) -> Bool {
    return CGAffineTransformEqualToTransform(lhs, rhs)
}
于 2016-08-22T15:04:49.350 回答