使用 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;
    };
}

有很多问题。首先,当我最初旋转到横向时,它只进行一次转换,在此配置中,它只是缩放它。

第二个问题是当我旋转到纵向时它要求旋转但它从不旋转。但是我可以在左风景和右风景之间来回移动并且它可以正确旋转。任何帮助将不胜感激

您实质上是将旋转变换替换为缩放变换。为了应用两者,您需要使用 CGAffineTransformConcat().

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

至于第二部分,您不需要应用另一个旋转,而是使用 CGAffineTransformIdentity.

将其设置为默认值
case UIDeviceOrientationPortrait:
    CGAffineTransform scale = CGAffineTransformMakeScale(0.5,0.5);
    self.videoView.transform = CGAffineTransformConcat(CGAffineTransformIdentity, scale);
    break;

试试这个

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