2016-03-20 27 views
0

UIView bir UIViewController içinde var UIView AVCaptureSession kullanarak fotoğraf çekmek için kullanılır.Döndürüldükten sonra görünümü düzgün şekilde göster

Bu yüzden UIView cihazımın cihazım döndüğünde dönmesini istemedim, bunu uygulamak için bu kodu yazdım. Ben rotasyon benim kamera UIView ve diğer UIViews sorunsuz döndürmek üzerinde herhangi bir etkisi yoktur döndüğünde portre modunda

-(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); 
}]; 
} 

benim UIView tam ekran açılır, Ama sorun benim kamera UIView olduğu yatay moda dönme üzerindedir Tam ekran değil ve ekranda rasgele boyut alır, Ne yapıyorum yanlış?

Not: Ben z ekseninde döndürülmüş değildi sanki kamera görüntüsünü film şeridi

+0

Otomatik düzenleri devre dışı bırakmayı denediniz mi? – atulkhatri

+0

Otomatik düzeni devre dışı bırakamıyorum Yakalama düğmesi olan diğer UIView cihazımın düzgün bir şekilde döndürülmesini istiyorum –

cevap

0

Otomatik Düzen paftalar kullanılarak görünümü tasarladık.

Kamera görünümü için otomatik düzeni kullanmamanızı ve programlı olarak & kamera görüntüsü oluşturmamanızı öneririm. Ardından otomatik düzenleme kısıtlamaları ile uğraşmadan çerçevesini animateAlongsideTransition bloğunda değiştirebilirsiniz.

- (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); 


           }]; 


} 
İlgili konular