2016-03-20 26 views
0

私はUIViewController内にUIViewを持っており、UIViewはAVCaptureSessionを使用して写真をキャプチャするために使用されます。回転後にビューを正しく表示する

私はこのコードを書いたので、デバイスを回転させたときにUIViewが回転しないようにしました。ポートレートモードで

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator 
{ 
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; 
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { 
    CGAffineTransform deltaTransform = coordinator.targetTransform; 
    CGFloat deltaAngle = atan2f(deltaTransform.b, deltaTransform.a); 
    CGFloat currentRotation = [[self.camera.layer valueForKeyPath:@"transform.rotation.z"] floatValue]; 
    currentRotation += -1 * deltaAngle + 0.0001; 
    [self.camera.layer setValue:@(currentRotation) forKeyPath:@"transform.rotation.z"]; 
} 
completion:^(id<UIViewControllerTransitionCoordinatorContext> context) { 
    CGAffineTransform currentTransform = self.camera.transform; 
    currentTransform.a = round(currentTransform.a); 
    currentTransform.b = round(currentTransform.b); 
    currentTransform.c = round(currentTransform.c); 
    currentTransform.d = round(currentTransform.d); 
}]; 
} 

私は私のカメラのUIViewは回転が私のカメラのUIView上の任意の効果を持っていないと、他のUIViewsがスムーズに回転し、しかし、問題は、ランドスケープモードに回転にある回転したときに私のUIViewのは、フルスクリーンを開きますフルスクリーンではなく、画面上でランダムなサイズを取る、何が間違っている?

注:私はそれがz軸上で回転されなかったかのようにカメラビューをストーリーボード

+0

自動レイアウトを無効にしましたか? – atulkhatri

+0

自動レイアウトを無効にできませんキャプチャボタンがある他のUIViewが必要になるフラッシュボタンが適切に回転するようにする –

答えて

0

自動レイアウトをレイアウト使用してビューを設計しました。

カメラレイアウトに自動レイアウトを使用しないで、&カメラビューをプログラムで追加することをお勧めします。 次に、自動レイアウト制約を処理せずに、animateAlongsideTransitionブロックでそのフレームを変更できます。

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    // Create the camera view 
    CGSize screenSize = [[UIScreen mainScreen] bounds].size; 
    self.camera = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenSize.width, screenSize.height)]; 
    [self.view addSubview:self.camera]; 
} 


-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator 
{ 
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; 



    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { 
     CGAffineTransform deltaTransform = coordinator.targetTransform; 
     CGFloat deltaAngle = atan2f(deltaTransform.b, deltaTransform.a); 
     CGFloat currentRotation = [[self.camera.layer valueForKeyPath:@"transform.rotation.z"] floatValue]; 
     currentRotation += -1 * deltaAngle + 0.0001; 
     [self.camera.layer setValue:@(currentRotation) forKeyPath:@"transform.rotation.z"]; 

     // Change the camera view's frame to match the screen 
     CGSize screenSize = [[UIScreen mainScreen] bounds].size; 
     self.camera.frame = CGRectMake(0, 0, screenSize.width, screenSize.height); 

    } 
           completion:^(id<UIViewControllerTransitionCoordinatorContext> context) { 
            CGAffineTransform currentTransform = self.camera.transform; 
            currentTransform.a = round(currentTransform.a); 
            currentTransform.b = round(currentTransform.b); 
            currentTransform.c = round(currentTransform.c); 
            currentTransform.d = round(currentTransform.d); 


           }]; 


} 
関連する問題