使用 CGAfflineTransformMakeScale/Rotation 只做一個動作 (Using CGAfflineTransformMakeScale/Rotation only does one action)


問題描述

使用 CGAfflineTransformMakeScale/Rotation 只做一個動作 (Using CGAfflineTransformMakeScale/Rotation only does one action)

當用戶將屏幕旋轉為橫向時,我正在嘗試使視頻旋轉並放大。

‑ (void) orientationChanged:(NSNotification *)note
{
    bool switchedLeft;
    UIDevice * device = note.object;
    switch(device.orientation)
    {
        case UIDeviceOrientationPortrait:
            self.videoView.transform=CGAffineTransformMakeScale(0.5,0.5);

            if (switchedLeft) {
                self.videoView.transform=CGAffineTransformMakeRotation(‑M_PI_2);

            }else{
                self.videoView.transform=CGAffineTransformMakeRotation(M_PI_2);
            }
            break;
        case UIDeviceOrientationLandscapeLeft:
            self.videoView.transform=CGAffineTransformMakeRotation(M_PI_2);
            self.videoView.transform=CGAffineTransformMakeScale(2.0, 2.0);
            switchedLeft=true;
            break;

        case UIDeviceOrientationLandscapeRight:
            self.videoView.transform=CGAffineTransformMakeRotation(‑M_PI_2);
            self.videoView.transform=CGAffineTransformMakeScale(2.0, 2.0);
            switchedLeft=false;
            break;

        default:
            break;
    };
}

存在許多問題。首先,當我最初旋轉到橫向時,它只進行一次轉換,在這種配置中,它只是縮放它。

第二個問題是,當我旋轉到縱向時,它需要旋轉,但它從不旋轉。但是我可以在橫向左側和橫向右側之間來回移動並且它可以正確旋轉。任何幫助將不勝感激


參考解法

方法 1:

You are essentially replacing the rotation transform with scale transform. In order to apply both, you need to use CGAffineTransformConcat().

CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI_2);
CGAffineTransform scale = CGAffineTransformMakeScale(2.0, 2.0);
self.videoView.transform = CGAffineTransformConcat(rotate, scale);

As for the second part, you don't need to apply another rotation, instead set it to default using CGAffineTransformIdentity.

case UIDeviceOrientationPortrait:
    CGAffineTransform scale = CGAffineTransformMakeScale(0.5,0.5);
    self.videoView.transform = CGAffineTransformConcat(CGAffineTransformIdentity, scale);
    break;

方法 2:

try this

CGAffineTransform transform = CGAffineTransformRotate(self. videoView.transform, M_PI);
self. videoView.transform = transform;

(by Kyle GriffithZeMoonMoin Shirazi)

參考文件

  1. Using CGAfflineTransformMakeScale/Rotation only does one action (CC BY‑SA 2.5/3.0/4.0)

#objective-c #cgaffinetransform #iphone #iOS






相關問題

為什麼 NSWindow 或 NSView 實例處理它自己的鍵事件,而不是它的委託? (Why does an NSWindow or NSView instance handle its own key events, and not its delegate?)

在調用之前釋放了 didFinishSelector ASIHTTPRequest 的自定義委託類 (Custom delegate class for didFinishSelector ASIHTTPRequest being deallocated before called)

通過 IKImage 視圖預覽圖像 (Previewg images via IKImage View)

Gaya Jendela Kustom di Kakao (Custom Window Style in Cocoa)

Тонкія белыя лініі дадаюцца пры абрэзцы выявы (Objective-C OSX) (Thin white lines being added when cropping an image (Objective-C OSX))

Obj-C:遞歸:在堆棧上創建新對像或使用可變性 (Obj-C: Recursion: Making new objects on stack or use mutability)

XCode 4.6 顯示方法 + (void)beginAnimations:(NSString *)animationID context:(void *)context; 的內存洩漏警告 (XCode 4.6 shows a warning of memory leak for method + (void)beginAnimations:(NSString *)animationID context:(void *)context;)

單元格中不可見的 UITextField 已將 userInteractionEnabled 設置為 No (UITextField in cell that is not visible has userInteractionEnabled set to No)

Gửi nhật ký sự cố ứng dụng / nhật ký ứng dụng thông thường (Send app crash logs/regular app logs)

我的鍵盤默認值僅在我的應用程序中更改 (My keyboard default be change in only my App)

在復選框上單擊獲取表行 ID - 目標 c (On check box click get the table Row ID - Objective c)

iPhone SDK:檢查 UITableView 中每個對象的 ID 號並相應地更改徽章號 (iPhone SDK: Checking the ID number for each object in a UITableView and change the badge number accordingly)







留言討論