簡體   English   中英

圍繞錨點將圖像旋轉90度

[英]rotate image 90 degrees around anchor point

我想圍繞錨點將imageview旋轉90度。 您可以在這里看到我想要實現的目標。 在此處輸入圖片說明

我有這段代碼。

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"];
}

有一個視圖問題。 首先,當它旋轉90度時,立即轉回其原始狀態。 另外,我也不知道如何圍繞錨點旋轉它。

有什么幫助嗎?

嘗試這個:

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

您正在使用僅處理動畫部分的CABAsicAnimation 旋轉后旋轉視圖是您的責任。 因此,您應該在旋轉后更改視圖的transform屬性。

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

對於您的anchorPoint問題。 每個UIView是由支持CALayerCALayeranchorPoint屬性。 只需更改視圖的錨點,即可圍繞該點旋轉視圖。

anchorPoint默認為0.5,0.5。 在0.0和1.0之間更改它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM