簡體   English   中英

CGAffineTransformMakeRotation(M_PI_2)在控制台中生成錯誤:CGAffineTransformInvert:奇異矩陣

[英]CGAffineTransformMakeRotation(M_PI_2) generate error in console: CGAffineTransformInvert: singular matrix

我第一次轉動iphone時會轉動按鈕。 我第二次轉iphone失敗了。

- (void)configureViewsLandscapeMode
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;

    if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {

        [self.button setTransform:CGAffineTransformMakeRotation(M_PI_2)];

    } else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {


        [self.button setTransform:CGAffineTransformMakeRotation(-M_PI_2)];

    }
}

我讀了其他類似的答案:

UIView使用CGAffineTransformMakeScale縮放為0

CGAffineTransformInvert:奇異矩陣

我從IOS開始,我不明白這個問題。 我想了解問題而不是解決問題,我將不勝感激

嘗試這個 :

- (void)configureViewsLandscapeMode
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;

    if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {

        [self.button setTransform:CGAffineTransformRotate(CGAffineTransformIdentity, M_PI_2)];

    } else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {


        [self.button setTransform:CGAffineTransformRotate(CGAffineTransformIdentity, -M_PI_2)];

    }
}

制作旋轉動畫時,請確保不要更改視圖frame 例如,當使用自動調整大小或嘗試明確更改frame時,可能會發生這種情況。

如果您同時更改幀和變換,尤其是在動畫內部,iOS會嘗試從原始位置生成動畫到目標位置。 這涉及一些矩陣計算,如果涉及多個變化(例如frame ),則可能以錯誤結束。

暫無
暫無

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

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