2014-04-28 215 views
0

我想反轉我的UIImagePickerController,以便它能夠填充iPhone 5的屏幕,顯然,被倒置。這裏是我對UIImagePickerController的代碼:UIImagePickerController不旋轉和翻譯/縮放

- (void)applicationDidBecomeActive 
{ 

UIImagePickerController *imageViewPickerController = [[UIImagePickerController alloc] init]; 
imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 
imageViewPickerController.showsCameraControls = NO; 
imageViewPickerController.cameraViewTransform = CGAffineTransformMakeRotation(DEGREES_RADIANS(180)); 
imageViewPickerController.cameraViewTransform = CGAffineTransformMakeTranslation(0.0, 71.0); 
imageViewPickerController.cameraViewTransform = CGAffineTransformScale(imageViewPickerController.cameraViewTransform, 1.333333, 1.333333); 


[self presentViewController:imageViewPickerController 
        animated:NO 
       completion:NULL]; 


} 

如果我運行此代碼,我沒有得到任何倒置。如果我修改它,如下所示:

- (void)applicationDidBecomeActive 
{ 

UIImagePickerController *imageViewPickerController = [[UIImagePickerController alloc] init]; 
imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 
imageViewPickerController.showsCameraControls = NO; 
    imageViewPickerController.cameraViewTransform = CGAffineTransformMakeTranslation(0.0, 71.0); 
imageViewPickerController.cameraViewTransform = CGAffineTransformScale(imageViewPickerController.cameraViewTransform, 1.333333, 1.333333); 
imageViewPickerController.cameraViewTransform = CGAffineTransformMakeRotation(DEGREES_RADIANS(180)); 


[self presentViewController:imageViewPickerController 
        animated:NO 
       completion:NULL]; 


} 

它反轉,但只佔用了屏幕的320×320平方,不顧我的其他轉換。如果任何人都可以藉助一些專業知識來了解如何讓它遵循所有這些論點,我將不勝感激。

回答

1

你應該試着來連接所有你創建成一個變換的轉換,然後將其設置爲cameraViewTransform像這樣:

CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 71.0); 
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333); 
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180)); 
CGAffineTransform transform = CGAffineTransformConcat(translate, scale); 
transform = CGAffineTransformConcat(transform, rotate); 
imageViewPickerController.cameraViewTransform = transform; 
+0

CGAffineTransformMakeTranslation不是爲 – Alena

+0

在iOS版2中添加CGAffineTransformMakeTranslation iOS 6的工作有沒有機會有別的東西,是這個問題? – alex

+0

可能是我的答案http://stackoverflow.com/a/23893665/989896會幫助你。 – Alena

1

下面的代碼對我的作品(適用於iOS 6和7)。但請注意,我將imagePickerController.view添加爲佔位符視圖的子視圖。

CGSize screenSize = [UIScreen mainScreen].bounds.size; 

    CGFloat cameraAspectRatio = 3.0f/4.0f; 

    CGFloat scale = (screenSize.height/screenSize.width) * cameraAspectRatio; 

    CGFloat yOffset = (screenSize.height - screenSize.width/cameraAspectRatio)/2.0; 

    CGAffineTransform translate = CGAffineTransformMakeTranslation(0, yOffset); 
    CGAffineTransform fullScreen = CGAffineTransformMakeScale(scale, scale); 
    CGAffineTransform fullTranform = CGAffineTransformConcat(fullScreen, translate); 

    if(SYSTEM_VERSION_LESS_THAN(@"7.0")) 
    { 
     CGRect rect = self.imagePickerController.view.frame; 
     rect.size.height = screenSize.width/cameraAspectRatio; 
     rect.size.width = screenSize.width; 
     imagePickerController.view.frame = rect; 

     imagePickerController.view.transform = fullTranform; 
    } 
    else 
    { 
     imagePickerController.view.frame = [UIScreen mainScreen].bounds; 
     imagePickerController.cameraViewTransform = fullTranform; 
    } 

    [self.placeholder addSubview:imagePickerController.view];