2011-04-16 16 views

回答

1

如果您想採取簡單的方式,除UIInterfaceOrientation之外不支持任何方向,並且圖像將被正確顯示。

否則,您必須在您的willAnimateRotationToInterfaceOrientation:duration:方法中將翻譯應用到與預覽層相反的預覽層。例如,UIInterfaceOrientationLandscapeLeft是(IIRC)順時針旋轉90°。因此,將90°逆時針旋轉應用於預覽圖層以進行補償。

+0

如何申請一個旋轉視圖層? – MikeN 2011-04-16 22:49:46

+0

使用圖層的[affineTransform](http://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instm/CALayer/setAffineTransform :)或[transform](http://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instp/CALayer/transform)屬性。或者把它放在視圖中並使用視圖的[transform](http://developer.apple.com/library/ios/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/ UIView /變形)道具。 – Anomie 2011-04-16 22:52:56

0

這是我用:

- (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    [CATransaction begin]; 
    self.prevLayer.orientation = toInterfaceOrientation; //AVCaptureVideoPreviewLayer 
    self.prevLayer.frame = self.view.frame; 
    [CATransaction commit]; 

    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; 
}