当用户将屏幕旋转到横向时,我正在尝试使视频旋转并缩放。
- (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;
};
}
有很多问题。首先,当我最初旋转到横向时,它只进行一次变换,在此配置中它只是缩放它。
第二个问题是,当我旋转到肖像时,它需要旋转,但它从不旋转。然而,我可以在左侧景观和右侧景观之间来回移动,并且它可以正常旋转。任何帮助将不胜感激
答案 0 :(得分:2)
您实际上是使用缩放变换替换旋转变换。要同时应用这两者,您需要使用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;
答案 1 :(得分:0)
试试这个
CGAffineTransform transform = CGAffineTransformRotate(self. videoView.transform, M_PI);
self. videoView.transform = transform;