iphone sdk CGAffineTransform getting the angle of rotation of an object

前端 未结 5 1299
清酒与你
清酒与你 2020-11-27 04:19

how do i calculate the angle of rotation for any given object (ie a uiimageview)?

5条回答
  •  鱼传尺愫
    2020-11-27 04:53

    You can easily get the angle of the rotation like this:

    CGFloat angle = [(NSNumber *)[view valueForKeyPath:@"layer.transform.rotation.z"] floatValue];
    

    For example:

    view.transform = CGAffineTransformMakeRotation(0.02);
    CGFloat angle = [(NSNumber *)[view valueForKeyPath:@"layer.transform.rotation.z"] floatValue];
    NSLog(@"%f", angle); // 0.020000
    

    From the documentation:

    Core Animation extends the key-value coding protocol to allow getting and setting of the common values of a layer's CATransform3D matrix through key paths. Table 4 describes the key paths for which a layer’s transform and sublayerTransform properties are key-value coding and observing compliant

提交回复
热议问题