ios - 围绕 anchor 将图像旋转 90 度

标签 ios objective-c calayer cabasicanimation quartz-core

我想围绕一个 anchor 将 ImageView 旋转 90 度。你可以在这里看到我想要实现的目标。 enter image description here

我有这段代码。

CGFloat DegreesToRadians(CGFloat degrees)
{
    return degrees * M_PI / 180;
}

NSNumber* DegreesToNumber(CGFloat degrees)
{
    return [NSNumber numberWithFloat:
            DegreesToRadians(degrees)];
}
-(IBAction)rotate:(id)sender{
    CABasicAnimation *rotationAnimation = [CABasicAnimation
                                           animationWithKeyPath:@"transform.rotation.y"];

    [rotationAnimation setFromValue:DegreesToNumber(0)];
    [rotationAnimation setToValue:DegreesToNumber(90)];
    [rotationAnimation setDuration:3.0f];
    [rotationAnimation setRepeatCount:1];

    [[[self imgShare] layer] addAnimation:rotationAnimation forKey:@"rotate"];
}

有一个 View 问题。首先,当它旋转 90 度时,它会立即翻转回原来的状态。我也不知道如何围绕 anchor 转动它。

有什么帮助吗?

最佳答案

试试这个:

self.imgShare.transform = CGAffineTransformMakeRotation(M_PI/2);

关于ios - 围绕 anchor 将图像旋转 90 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17444391/

相关文章:

objective-c - Objective C 中单词中的所有第一个字母都大写吗?

iphone - 如何识别设备(唯一标识符、CFUUIDRef、设备 token ?)

ios - 自定义类型右栏按钮项之间的间距

ios - 针对大数据的 CoreData 优化

ios - 当前事件的时间戳/NSDate在UIKit中启动

PHP 的 openssl_sign 生成的签名与 SSCrypto 的签名不同

ios - 设置 layer.borderColor 时 UICollectionViewCell 边框消失

iphone - CALayer 的 display/drawRect 方法中到底应该发生什么?

cocoa - 绘制层 :inContext: draws background over content when using Layer-Hosting NSView

ios - UIButton action(rx.tap) 用 RxSwift 响应不同的 PublishSubjects